logto
logto copied to clipboard
How to correctly access scopes in the nextjs server action situation
I have configured the Config according to the document.
import { UserScope } from "@logto/next";
export const logtoConfig = {
endpoint: "https://auth.aice.chat/",
appId: "ej4nih6c4rm9jql612y5c",
appSecret: "4BJEw1akolM3zYmTh2CDcfu7idlPXdS1",
baseUrl: "http://localhost:3000", // Change to your own base URL
cookieSecret: "T0UoSIiPUIs9pO8Mpu74tRtiWmadwBHI",
cookieSecure: process.env.NODE_ENV === "production",
scopes: [
UserScope.CustomData,
UserScope.Roles,
UserScope.Email,
UserScope.Phone,
UserScope.Organizations,
UserScope.OrganizationRoles,
UserScope.Identities,
"read:app", // Already configured in the console.
],
resources: ["http://no.com/api"],
};
However, when I call
getLogtoContext(logtoConfig, {
getAccessToken,
});
The result does not include scopes.
I also tried using the /oidc/me
API, but it didn't return any scopes either.
{
"sub": "y7xm0wj0jv2p",
"name": "beyond",
"picture": null,
"updated_at": 1713879215359,
"username": null,
"created_at": 1713457888679,
"email": "[email protected]",
"email_verified": true,
"phone_number": null,
"phone_number_verified": false,
"identities": {},
...
}
The above is my test case. How can I retrieve user information with the scopes
parameter included?
When you call
getLogtoContext(logtoConfig, {
getAccessToken,
});
You can also pass the resource indicator as an additional param, like this:
getLogtoContext(logtoConfig, {
getAccessToken: true,
resource: 'http://no.com/api'
});
And if you provide the resource when requesting an access token, the access token will be in JWT format, where you can find scopes
as a token claim
This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This could definitely be clarified in the docs.
I just stumbled across this as well while trying to get JWTs for my backend.
This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.