Skip to content
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

How to correctly access scopes in the nextjs server action situation #5781

Open
Haiananan opened this issue Apr 23, 2024 · 2 comments
Open
Labels
pending-verification Something is still under investigation stale

Comments

@Haiananan
Copy link

Haiananan commented Apr 23, 2024

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": "1628089948@qq.com",
    "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?

@Haiananan Haiananan added the bug Something isn't working label Apr 23, 2024
@charIeszhao
Copy link
Member

charIeszhao commented Apr 28, 2024

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

@charIeszhao charIeszhao added pending-verification Something is still under investigation and removed bug Something isn't working labels Apr 28, 2024
Copy link

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.

@github-actions github-actions bot added the stale label May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-verification Something is still under investigation stale
Development

No branches or pull requests

2 participants