2016-05-18 28 views
0

シンプルなoauth2ライブラリを使用してトークンを取得していますが、acessトークンとIDトークンしかありません。Outlook APIリフレッシュトークン

リフレッシュトークンを取得するにはどうすればよいですか?

答えて

0

リフレッシュ・トークンは、許可サーバーによって発行され、それを発行するのは許可サーバーの裁量です。 Outlook APIについて言及して以来、リフレッシュトークン用のMicrosoft Graph APIを使用できます。

Outlook APIの更新トークンを取得する方法については、Outlook Dev CenterMicrosoft Graph APIをご覧ください。

ありがとう、 Soma。

+0

だから、トークンに沿ってリフレッシュ与えるべきI Azureへの定期購読はどうですか?他の方法はありませんか? – user2993349

0
function refresh_token($token) 
{ 
    // Build the form data to post to the OAuth2 token endpoint 
    $token_request_data = array(
    "grant_type" => 'refresh_token', 
    "refresh_token" => $token, 
    "redirect_uri" => 'https://login.microsoftonline.com/common/oauth2/token', 
    "resource" => "https://outlook.office365.com/", 
    "client_id" => self::$clientId, 
    "client_secret" => self::$clientSecret 
); 

    // Calling http_build_query is important to get the data 
    // formatted as Azure expects. 
    $token_request_body = http_build_query($token_request_data); 
    error_log("Request body: ".$token_request_body); 

    $curl = curl_init(self::$authority.self::$tokenUrl); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_POST, true); 
    curl_setopt($curl, CURLOPT_POSTFIELDS, $token_request_body); 
    /*custom*/ 
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 
    /*custom end*/ 
    $response = curl_exec($curl); 
    error_log("curl_exec done."); 

    $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); 
    error_log("Request returned status ".$httpCode); 
    if ($httpCode >= 400) { 
    return array('errorNumber' => $httpCode, 
       'error' => 'Token request returned HTTP error '.$httpCode); 
    } 

    // Check error 
    $curl_errno = curl_errno($curl); 
    $curl_err = curl_error($curl); 
    if ($curl_errno) { 
    $msg = $curl_errno.": ".$curl_err; 
    error_log("CURL returned an error: ".$msg); 
    return array('errorNumber' => $curl_errno, 
       'error' => $msg); 
    } 

    curl_close($curl); 

    // The response is a JSON payload, so decode it into 
    // an array. 
    $json_vals = json_decode($response, true); 
    error_log("TOKEN RESPONSE:"); 
    foreach ($json_vals as $key=>$value) { 
    error_log(" ".$key.": ".$value); 
    } 

    return $json_vals; 
} 
0

私は同じ問題がありました。 スコープパラメータ['offline_access'] 追加authUrlで追加する必要があります。

{access_type:'offline', approval_prompt: 'force'} 

これは、私がテナントIDを、必要とするMicrosoftグラフAPIを使用するためには、auth_tokensid_token

関連する問題