#api #rest #microsoft-graph #o-auth

graph-oauth

Microsoft Graph api oauth client for the graph-rs project

8 releases

new 0.2.1 Mar 19, 2023
0.2.0 Apr 22, 2022
0.1.3 Jan 31, 2022
0.1.0 Jun 12, 2021
0.0.1 Dec 13, 2020

#178 in Authentication

Download history 17/week @ 2022-11-27 40/week @ 2022-12-04 44/week @ 2022-12-11 34/week @ 2022-12-18 19/week @ 2022-12-25 27/week @ 2023-01-01 89/week @ 2023-01-08 101/week @ 2023-01-15 97/week @ 2023-01-22 122/week @ 2023-01-29 112/week @ 2023-02-05 113/week @ 2023-02-12 69/week @ 2023-02-19 47/week @ 2023-02-26 70/week @ 2023-03-05 30/week @ 2023-03-12

224 downloads per month
Used in graph-rs-sdk

MIT license

150KB
2.5K SLoC

graph-oauth

OAuth client for Microsoft Graph and the graph-rs project.

See the project on GitHub.

Authorization Flows and Microsoft Graph

1. Token Flow - v1.0
2. Code Flow - v1.0
3. Authorization Code Grant - v1.0 and beta
4. Open ID - v1.0 and beta
5. Implicit - v1.0 and beta
6. Client Credentials - v1.0 and beta
7. Resource Owner Password Credentials - v1.0 and beta

For more examples see the example's directory in the graph-rs project on GitHub.

For more information on Microsoft graph and OAuth 2.0 authorization flows see: https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-app-types

use graph_oauth::oauth::OAuth;

fn main() {
    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");

    let mut request = oauth.build().authorization_code_grant();
    
    // Opens the default browser.
    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:
    let mut request = oauth.build().authorization_code_grant();
    let access_token = request.access_token().send().unwrap();
    println!("{:#?}", access_token);
}

Dependencies

~16–25MB
~559K SLoC