我正在尝试将angular-oauth2-oidc库与Auth0 和 Github集成。请随时记住,我从 Auth0/Github UI 方面选择了所有范围(只是为了安全起见)。
使用最新功能
我正在使用angular-oauth2-oidc必须提供的最新功能。
- 例如,我正在使用代码流,即:
responseType: 'code',
- 此外,我为我的 customQueryParams 使用了适当的受众,例如
customQueryParams: {
// API identifier configured in Auth0 - Put made up audience here
audience: 'https://dev-51246k0z.us.auth0.com/api/v2/',
},
可以在此处查看完整的 auth.config.ts 文件:
import { AuthConfig } from 'angular-oauth2-oidc';
export const authConfig: AuthConfig = {
// Your Auth0 app's domain
// Important: Don't forget to start with https://
// AND the trailing slash!
issuer: 'https://id.company-name.com/',
// The app's redirectUri configured in Auth0
redirectUri: window.location.origin ,
// URL of the SPA to redirect the user after silent refresh
silentRefreshRedirectUri: window.location.origin,
useSilentRefresh: true,
// The app's clientId configured in Auth0 - example client id
clientId: 'A0tLAYYSyGRtwyF4wlVh49jmLZCW8pVQ',
// Scopes ("rights") the Angular application wants get delegated
scope: 'openid profile email offline_access read:roles',
// Using Authorization Code Flow
// (PKCE is activated by default for authorization code flow)
responseType: 'code',
// Your Auth0 account's logout url
// Derive it from your application's domain
logoutUrl: 'https://id.company-name.com/logout',
customQueryParams: {
// API identifier configured in Auth0
audience: 'https://dev-51246k0z.us.auth0.com/api/v2/',
},
silentRefreshTimeout: 5000, // For faster testing
timeoutFactor: 0.25, // For faster testing
sessionChecksEnabled: true,
showDebugInformation: true, // Also requires enabling "Verbose" level in devtools
clearHashAfterLogin: false, // https://github.com/manfredsteyer/angular-oauth2-oidc/issues/457#issuecomment-431807040,
nonceStateSeparator : 'semicolon' // Real semicolon gets mangled by IdentityServer's URI encoding
};
我遇到的自定义范围问题
我遇到的问题是我为角色指定的自定义范围不是通过使用 Auth0 Github 社交连接来实现的。我的范围字段如下所示:
// Scopes ("rights") the Angular application wants get delegated
scope: 'openid profile email offline_access read:roles',
,但access_token
永远不会包括超出的范围openid profile email offline_access
。即不会给应用程序read:roles
导致 Auth0 角色 API 失败的范围/权限。
我的 Github 社交登录正在运行。该应用程序将我重定向到 Github,它要求我登录,然后指定 Github 应用程序所需的范围。
如果这个问题不够清楚,请随时发表评论,并将整理问题。