-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] RequiredScope doesn't work (for web APIs called by daemon apps) #1571
Comments
@Anakael I cannot repro: Can you share what you have in your Startup.cs? Thanks. |
I did nothing special for it except the authentication by jwt token. Did I miss something? |
I would need more information from your Startup.cs. Do you have the same content as when you do |
I've run into this issue as well, repro'd in 2 different projects. What's interesting is it works/doesn't work as follows:
So for now i'm using the VerifyUserHasAnyAcceptedScope method but would prefer to use the attribute |
Thanks for the explanation, @spacattac. This is by design (and to follow the protocol), but I realize that the design might not be very good, so I'm tempted to start a discussion with the group to simplify things What happens is:
But from the point of view of the client app, in both cases you request scopes (you are exposed to app roles when you do the app registration though). This is all explained in Protected web API: Verify scopes and app roles Question for you:
|
Thanks @jmprieur . i had read that msft docs link and i didn't really understand why the daemon app couldn't/wouldn't use the scope the same way and didn't understand what an app role is/was. in reading more about Azure AD last night i did learn about the app registration and that app role designation is part of that registration. that explains why i didn't/don't really know what it is - i'm not actually using Azure AD and instead am using Okta for OIDC+OAuth and the daemon app registration doesn't have an app role. i can use Access Policies on the Okta auth server to grant the scopes to an app using client_credentials just like i can to an app acting on behalf of the user with authorization_code flow. |
Thanks for the explanation, @spacattac. |
Thanks @jmprieur - yes, okta does generate the scope (scp) claim. i don't understand why the call to HttpContext.VerifyUserHasAnyAcceptedScope(scopeRequiredByApi); works for me but [RequiredScopes(scopeRequiredByApi)] does not. It seems to me there should be parity with these. |
I guess we'd need to see the structure of the token to understand this question? Are you using app.UseAuthorization? Did you customize the Authorization policies? |
@jmprieur i'll grab some code and/or screen snippets to share/show ... |
here's a snippet of scope check working as expected via the method but not the attribute. i am using app.UseAuthorization. and in this project i do have 1 policy added but it's not used in the endpoint/method in this example. also, the other project where i've repro'd this same behavior does not have any additional policies.
|
@spacattac : in the claims, the scope provided by Okta (item 7) has a value "access_token", whereas you want "documents.read". That's the reason. |
@jmprieur - not exactly .... what i'm showing you above is i've intentionally left out the documents.create scope and i'm showing you how the [RequiredScopes("documents.create")] attribute did NOT block the call yet the VerifyUserHasAnyAcceptedScope("documents.create") DID block and returns Forbidden. why is there not parity between these two? |
@jmprieur Yes, I peeked inside Microsoft's code and saw |
Which version of Microsoft Identity Web are you using?
1.21.1
Where is the issue?
Is this a new or an existing app?
This is a new app or an experiment.
Repro
Expected behavior
Request finished with 403 code when pass scope
myScopeNameM2M
.Actual behavior
Request finishes with 200 code
Additional context / logs / screenshots / link to code
Works as expected.
The text was updated successfully, but these errors were encountered: