Accessing Microsoft Graph API without using login page

后端 未结 4 1843
闹比i
闹比i 2020-12-10 11:44

I would like to access a user\'s one drive to upload a document or retrieve a document using Graph API. I\'ve seen multiple examples over the net which requires using the st

4条回答
  •  抹茶落季
    2020-12-10 11:59

    I've found the documentation is not helpful, especially in terms of trying to acces the Graph API in the application context. But, I managed to get the access token in the context of the application here:

    private static async Task AcquireToken()
    {
        var tenant = "yourtenant.onmicrosoft.com";
        var resource = "https://graph.microsoft.com/";
        var instance = "https://login.microsoftonline.com/";
        var clientID = "YourappID";
        var secret = "YourAppSecret";
        var authority = $"{instance}{tenant}";
        var authContext = new AuthenticationContext(authority);
        var credentials = new ClientCredential(clientID, secret);
        var authResult = await authContext.AcquireTokenAsync(resource, credentials);
        return authResult.AccessToken;
    }
    

提交回复
热议问题