简体   繁体   中英

Authorization with new Office365 API

I have started an attempt at utilizing the new Office 365 API. I am having some issues though.

I have successfully retrieved an access_token but the documentation doesn't tell me what to do with it.

Has anyone else done this successfully, or alternatively can you have a quick read over the documentation and shed some light on it?

Thanks

Edit: Forgot the link - http://msdn.microsoft.com/en-us/library/office/dn605896.aspx

The documentation to use PHP and Office365 API according to my research is almost inexistent but... I was able to use Office API by using this PHP class to process the oauth connection:

http://www.phpclasses.org/package/7700-PHP-Authorize-and-access-APIs-using-OAuth.html

Hope it helps!

Using this class you will be able to access like this:

// Oauth to Office365
$office_oauth = new oauth_client_class;
$office_oauth->debug = true;
$office_oauth->debug_http = false;

$office_oauth->redirect_uri = 'http://' . $_SERVER['HTTP_HOST'];

$office_oauth->client_id = 'YOUR_CLIENT_ID';
$office_oauth->client_secret = 'YOUR_CLIENT_SECRET';

$office_oauth->dialog_url = 'https://login.windows.net/common/oauth2/authorize?response_type=code&client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}&state={STATE}&scope={SCOPE}&resource='.UrlEncode("https://outlook.office365.com/");
$office_oauth->access_token_url = 'https://login.windows.net/common/oauth2/token';

$office_oauth->oauth_version = 2;
$office_oauth->url_parameters = 1;
$office_oauth->authorization_header = 1;
$office_oauth->exit = 0;

$office_oauth->scope = 'YOUR_SCOPES';

if (($officeSuccess = $office_oauth->Initialize())) {

    $officeSuccess = $office_oauth->Process();
    $officeSuccess = $office_oauth->Finalize($officeSuccess);
}

if ($office_oauth->exit) {
    exit;
}

The access token should be embedded in the request when calls the resource (please find the 9th). So I'm guessing you need to provide your access token in your request headers, for instance:

context.SendingRequest2 += (s, e) => { e.RequestMessage.SetHeader("Authorization", "Bearer " + accessToken); };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM