AdobeDocs / adobe-dev-console

Apache License 2.0
21 stars 123 forks source link

.NET sample code generates an "invalid_scope" error #54

Closed Trazzmonger closed 1 year ago

Trazzmonger commented 1 year ago

Expected Behaviour

The sample code is supposed to build a JWT object and then pass it in an Adobe API call to get back an "access token".

Actual Behaviour

Such API calls are failing with a response.Content of: "{\"error_description\":\"The metascopes in the JWT are not a subset of the metascopes in the binding.\",\"error\":\"invalid_scope\"}"

Reproduce Scenario (including but not limited to)

Use the sample code to make the API call. NOTE: I successfully get an Access Token when I copy-paste my Adobe API Project's private key into the GUI box provided for such testing at https://developer.adobe.com/console/projects/374378/4566206088344859311/apis/AdobeIOManagementAPISDK/details.

Steps to Reproduce

  1. Prepare the requisite Adobe API "Project" (e.g., https://developer.adobe.com/console/projects/374378/4566206088344859311/overview)
  2. Use that project to provide the necessary arguments for (using the sample code to make a) REST API call ... leveraging an older version of the RestSharp open source library (e.g., v106.13.0) due to another issue (https://github.com/AdobeDocs/adobe-dev-console/issues/50)

Platform and Version

Windows 10 running Microsoft Visual Studio 2019.

Sample Code that illustrates the problem

Current code leveraging an older version of the RestSharp library (e.g., v106.13.0).

Logs taken while reproducing problem

n/a

adorton-adobe commented 1 year ago

Hello,

I created PR #57 to suggest some updates to the C# sample based on your bug reports.

However, that does not resolve the scope error you're seeing. You need to make sure you provide the right scope URI(s). You can find the scope for a given service on the Adobe Developer Console:

  1. Log into the developer console
  2. Open your project
  3. Click Service Account (JWT)
  4. Open the Generate JWT tab
  5. Your scope is in the payload. It will differ depending on what service is associated with the credentials. There may be more than one.

For example, I mostly work with the User Management API, so the scope I'd provide is

https://ims-na1.adobelogin.com/s/ent_user_sdk

Once you set the scope(s) associated with your project you should stop getting the error.

Trazzmonger commented 1 year ago

Thank you, thank you, thank you - that five-step procedure you provided worked!!!

Apparently my payload requires the ent_adobeio_sdk scope (which wasn't in the C#.NET sample code - the C#.NET sample code lists the ent_user_sdk scope ... but not ent_adobeio_sdk).

I strongly recommend you add that five-step process to the sample code and/or documentation. (And, my apologies if it's already documented somewhere that I simply overlooked.)