Search code examples
c#azure-webjobs

How to Generate One drive business Token using graph api on web job without login prompt


Due to this issue, token is not generate through job so we need to generate token from another utility through web prompt and update that token in system and then after we process that job


Solution

  • Since you are getting information from the drive I assume that you would need the user context.

    You could get the OAUTH access token by passing the credentials enter image description here

    A sample request will look like below :

    POST {tenant}/oauth2/v2.0/token
    Host: login.microsoftonline.com
    Content-Type: application/x-www-form-urlencoded
    
    client_id=<YOUR CLIENT ID>
    &scope=user.read%20openid%20profile%20offline_access
    &username=<YOUR USERNAME>
    &password=<YOUR PASSWORD>
    &grant_type=password
    

    Reference : https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth-ropc

    The access token generated will have both app and user context.

    Alternate :

    An App only Token. Please check this. In this case you can request a token. However, the token will not have any user context. You will have to give the Application Permission to the required scopes.

    enter image description here

    You could use the get drive method to get a specific drive info.

    enter image description here