question

AlexanderSvarnik-4009 avatar image
0 Votes"
AlexanderSvarnik-4009 asked JanardhanaVedham-MSFT commented

Android Graph SDK. Access is denied. Check credentials and try again

Hello.

Set up Graph SDK for Android as per instructions.
Added SAML - user is authorized and token is present.

Code that calls API:
mClient.me().contacts().buildRequest().async
.thenAccept {
Log.d("TEST", "collection=$it")
}
.exceptionally {
Log.d("TEST", "error=${it.message}")
null
}

Logcat:
E/global: CoreHttpProvider[processResponse] - 493Graph service exception Error code: ErrorAccessDenied
E/global: CoreHttpProvider[processResponse] - 493Error message: Access is denied. Check credentials and try again.
E/global: CoreHttpProvider[processResponse] - 493
E/global: CoreHttpProvider[processResponse] - 493GET https://graph.microsoft.com/v1.0/me/contacts
E/global: CoreHttpProvider[processResponse] - 493SdkVersion : graph-java/v5.15.0
E/global: CoreHttpProvider[processResponse] - 493
E/global: CoreHttpProvider[processResponse] - 493
E/global: CoreHttpProvider[processResponse] - 493403 : Forbidden
E/global: CoreHttpProvider[processResponse] - 493[...]
E/global: CoreHttpProvider[processResponse] - 493
E/global: CoreHttpProvider[processResponse] - 493[Some information was truncated for brevity, enable debug logging for more details]
E/global: Throwable detail: com.microsoft.graph.http.GraphServiceException: Error code: ErrorAccessDenied
Error message: Access is denied. Check credentials and try again.

     GET https://graph.microsoft.com/v1.0/me/contacts
     SdkVersion : graph-java/v5.15.0


     403 : Forbidden
     [...]

     [Some information was truncated for brevity, enable debug logging for more details]


Permissions for Application on Azure:
178947-screen-shot-2022-03-01-at-200404.png

178889-screen-shot-2022-03-01-at-200412.png



Thank you.

microsoft-graph-profilemicrosoft-graph-contacts
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @@AlexanderSvarnik-4009,

Adding relevent tag "microsoft-graph-contacts" to this post.

If the below provided answer is helpful to you, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.



0 Votes 0 ·
JanardhanaVedham-MSFT avatar image
0 Votes"
JanardhanaVedham-MSFT answered

Hi @AlexanderSvarnik-4009,

As you can see below, I am able to replicate the same issue in Graph Explorer Application. As documented in List contacts API , you would have to grant "Contacts.Read" or "Contacts.ReadWrite" micosoft graph permissions to get a contact collection from the default contacts folder of the signed-in user.

Error Replication from Graph Explorer Application without Contacts.Read" or "Contacts.ReadWrite" micosoft graph permissions granted:
Example:
178906-image.png

178965-image.png

Succesful response in Graph Explorer Application after granting Contacts.Read" micosoft graph permissions :
Example:
179011-image.png

Hope this helps.

If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.



image.png (68.5 KiB)
image.png (42.3 KiB)
image.png (102.3 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AlexanderSvarnik-4009 avatar image
0 Votes"
AlexanderSvarnik-4009 answered AlexanderSvarnik-4009 edited

Hi @JanardhanaVedham-MSFT

Thank you for response.

I ran Graph Explorer and see the same error. Based on your response I need to add permissions for Contacts.

Just want to describe how our android app is added:
1. On production corporate tenant A - application was created and registered as we are owner and creator of this app. There is generated Application_ID.
2. On Test tenant B - I have full admin access to Azure and want to make user from tenant B use our app with Contacts access.

Regarding your screenshot ListContacts I can't find a place where to allow Contacts.Read and Contacts.ReadWrite.
I added these permissions at:

179238-screen-shot-2022-03-02-at-150053.png
179220-screen-shot-2022-03-02-at-145230.png

This didn't help. Graph explorer still returns the same error.

According to this please help with these questions:
1. Where should I allow Contacts.Read and Contacts.ReadWrite
2. I I should allow this for our application - on what tennant? On Tenant A that is creator of app? Or Tenant B that is using app? On tenant B I couldn't find buttons that will add these permissions. On my original question post I added screenshots from Tenant B and permissions list.

Thank you a lot for helping.

Regards,
Alex.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AlexanderSvarnik-4009 avatar image
0 Votes"
AlexanderSvarnik-4009 answered JanardhanaVedham-MSFT commented

Hi @JanardhanaVedham-MSFT

Please answer me, I couldn't find that section to enable permissions.

Regards,
Alex.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JanardhanaVedham-MSFT avatar image
1 Vote"
JanardhanaVedham-MSFT answered JanardhanaVedham-MSFT edited

Hi @AlexanderSvarnik-4009 ,

Sorry for the delayed response.

You would need to configure the microsoft graph permissions for the application using which the authentication is being done and the access token is generated. Below are the steps to be followed to grant Microsoft graph permissions for the registered app in Azure AD.
181009-image.png
181029-image.png
181039-image.png
If you are using application permissions scope in your application then you would have choose "Application Permissons" section
181062-image.png

If you are using delegated permissions scope in your application then you would have choose "Deleted Permissons" section instead of "Application Permissions"

181044-image.png
181040-image.png

As shown in the above screenshot, Admin must grant admin consent for "Contacts.Read" or "Contacts.ReadWrite" application or delegated permissions.

Additional Documentation on App Registration & Authentication and authorization basics for Microsoft Graph :
https://docs.microsoft.com/en-us/graph/auth/auth-concepts
https://docs.microsoft.com/en-us/graph/auth-register-app-v2
https://docs.microsoft.com/en-us/graph/auth-v2-user
https://docs.microsoft.com/en-us/graph/auth-v2-service

Hope this helps.

If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.


image.png (90.0 KiB)
image.png (68.7 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AlexanderSvarnik-4009 avatar image
0 Votes"
AlexanderSvarnik-4009 answered JanardhanaVedham-MSFT commented

Hi @JanardhanaVedham-MSFT

Thank you a lot for help. Now android app can use Graph API for these purposes.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @AlexanderSvarnik-4009 ,

Thanks for the update. Glad to know that the issue has been resolved for you.

0 Votes 0 ·