I tried below github sample for Azure AD Authentication and successfully getting access token with proper call back URL.
https://github.com/Microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/18.bot-authentication
Modified and Configured Web.config Keys as per my application created in https://apps.dev.microsoft.com
<add key="ActiveDirectory.Mode" value="v1" />
<add key="ActiveDirectory.ResourceId" value="https://graph.microsoft.com" />
<add key="ActiveDirectory.EndpointUrl" value="https://login.microsoftonline.com" />
<add key="ActiveDirectory.Tenant" value="xyz-xyz" />
<add key="ActiveDirectory.ClientId" value="xyz-xyz" />
<add key="ActiveDirectory.ClientSecret" value="xyz-xyz" />
<add key="ActiveDirectory.RedirectUrl" value="http://localhost:3979/api/Callback" />
<add key="ActiveDirectory.Scopes" value="Calendars.Read,Calendars.ReadWrite,Contacts.Read,Contacts.ReadWrite,Mail.Read,Mail.ReadWrite,User.Read" />
I had crossed checked access token that i received jwt.ms. It is a valid token with scopes defined exactly as i defined in web.config.
I am able to get User Profile data from API by passing token but while trying to call "Contacts" of user, I am getting below error.
{
"error": {
"code": "ResourceNotFound",
"message": "Resource could not be discovered.",
"innerError": {
"request-id": "6f0f3ec9-76c9-4662-ac25-0bc73f887268",
"date": "2019-03-02T17:23:35"
}
}
}
Code calling Contact API call.
//Get Logged in user contacts
public async Task<IUserContactsCollectionPage> GetMyContactsAsync()
{
var graphClient = GetAuthenticatedClient();
IUserContactsCollectionPage contacts = await graphClient.Me.Contacts.Request().GetAsync();
return contacts;
}
FYI: Displayed Sign In card in emulator Authorize sample URL is like below
https://login.microsoftonline.com/a76b43b0-3088-4c56-ba0d-01f317b1f18c/oauth2/authorize?resource=https:%2F%2Fgraph.microsoft.com&client_id=XYZ&response_type=code&haschrome=1&redirect_uri=http:%2F%2Flocalhost:3979%2Fapi%2FCallback&x-client-SKU=PCL.Desktop&x-client-Ver=3.13.9.1126&x-client-CPU=x64&x-client-OS=Microsoft+Windows+NT+10.0.16299.0&state=<stateID>