0

In the following code I'm getting a null reference exception when the control tries to execute the GetAsync() request.

public static async Task<DialogTurnResult> OnBehalfOf(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
    try
    {

        IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
        .Create(clientId)
        .WithRedirectUri(redirectUri)
        .WithClientSecret(clientSecret)
        .Build();

        OnBehalfOfProvider authProvider = new OnBehalfOfProvider(confidentialClientApplication, scopes);
        HttpProviderTeamsAccess temp = new HttpProviderTeamsAccess();
        GraphServiceClient graphClient = new GraphServiceClient(authProvider);

        var usr = await graphClient.Me.Request().GetAsync();
        var a = usr;
        //var reply_User_Name = MessageFactory.Text(user.DisplayName.ToString());
        //await stepContext.Context.SendActivityAsync(reply_User_Name, cancellationToken);
    }
    catch (Exception ex)
    {
        var reply_User_Name = MessageFactory.Text(ex.Message.ToString());
        await stepContext.Context.SendActivityAsync(reply_User_Name, cancellationToken);
    }
    return null;
}
Milo
  • 3,002
  • 9
  • 25
  • 40

1 Answers1

1

When using the OnBehalfOfProvider you have to say which user you are making the call on behalf of.

var usr = await graphClient.Me.Request().WithUserAssertion(<bearer token from incoming auth header>).GetAsync();
Darrel Miller
  • 129,370
  • 30
  • 183
  • 235