[][src]Crate graph_oauth

OAuth client for the graph-rs project.

See the project on GitHub.

OAuth

An authorization and access token client for Microsoft Graph and the OAuth 2.0 authorization framework. This project is specifically meant to be used for the Microsoft Graph Api.

Disclaimer

Using this API for other resource owners besides Microsoft may work but functionality will more then likely be limited.

Example

use graph_oauth::oauth::OAuth;
let mut oauth = OAuth::new();
oauth
    .client_id("<YOUR_CLIENT_ID>")
    .client_secret("<YOUR_CLIENT_SECRET>")
    .add_scope("files.read")
    .add_scope("files.readwrite")
    .add_scope("files.read.all")
    .add_scope("files.readwrite.all")
    .add_scope("offline_access")
    .redirect_uri("http://localhost:8000/redirect")
    .authorize_url("https://login.microsoftonline.com/common/oauth2/v2.0/authorize")
    .access_token_url("https://login.microsoftonline.com/common/oauth2/v2.0/token")
    .refresh_token_url("https://login.microsoftonline.com/common/oauth2/v2.0/token")
    .response_type("code")
    .logout_url("https://login.microsoftonline.com/common/oauth2/v2.0/logout")
    .post_logout_redirect_uri("http://localhost:8000/redirect");

Get the access code for the authorization code grant by sending the user to log in using their browser.

This example is not tested
let mut request = oauth.build().authorization_code_grant();
let _ = request.browser_authorization().open();

The access code will be appended to the url on redirect. Pass this code to the OAuth instance:

oauth.access_code("<ACCESS CODE>");

Perform an authorization code grant request for an access token:

This example is not tested
let mut request = oauth.build().authorization_code_grant();

let access_token = request.access_token().send().unwrap();
println!("{:#?}", access_token);

Modules

jwt
oauth