Cannot access the management API #1971
Replies: 4 comments 4 replies
-
@frenetisch-applaudierend did your .NET application handles the OIDC interaction internally? (Since we do not have a .Net SDK yet, I assume the sign-in flow is handled internally by the IdentityModal you pasted here.)
Like our React SDK. This is the same as you set for the OidcClientOptions so far. However when trying to retrieve a specific access token for some API. You will have to let the Logto server know which API resource's access token you are asking for. You will only get the default access_token from the initial sign-in authorization flow. You will have to ask for an access_token exclusively for the API using the refresh token returned the first time. That might be the gap. It would be helpful if you could get the exact /auth/token request body. We can check if the resource param is present. Let me know if these make any sense to you. |
Beta Was this translation helpful? Give feedback.
-
This is where I can locate that the auth code is redeemed and exchanged for a token. As you can see no resource is being passed. So the default access token you received is not in JWT format, also not intent for any custom API use. Looks like the IdentityModel allows you to pass in additional params to the refreshToken request just like we did in our SDKs: Once you first login and get the refresh token from the token response. Can you try to call this RefreshTokenAsync with additional back-channel params: sth like: var refreshResult = await _oidcClient.RefreshTokenAsync(currentRefreshToken, { resource: "https://api.logto.io"} ); The will ask Logto to issue a new access token exclusively for the usage of the management API. See how it goes. |
Beta Was this translation helpful? Give feedback.
-
Interesting this works well for me with the One more thing to check, make sure the resource is passed properly at the very beginning auth request. Can you check the signIn URI being generated Also, looks like IdentityModal Client has a refreshTokenAsync method? |
Beta Was this translation helpful? Give feedback.
-
@frenetisch-applaudierend how does it go? |
Beta Was this translation helpful? Give feedback.
-
I'm trying to access the management api from a .NET sample application adapted from IdentityModel.OidcClient.Samples.
Logto is running locally in docker, on http://localhost:3001. I have setup an initial admin user (alice) and added a native application.
Using the following configuration of OidcClient I can get an identity token as well as an access token:
The decoded identity token JWT looks like this:
The access token does not seem to be a JWT.
I can pass the access token to
/oidc/me
to get user information.When passing the access token to
/api/users
however I get the following error (401):If I pass the identity token the error message is different (401):
The documentation mentions that the
aud
must be "https://api.logto.io", but I don't know how to get such a token. Theaud
seems always to match the application id, and using "https://api.logto.io" as application id does also not work, since there is no such app.Any help to what I'm doing wrong is much appreciated!
Beta Was this translation helpful? Give feedback.
All reactions