问题描述
我正在尝试将 angular-oauth2-oidc 库与 Auth0 and 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/',},
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 Social Connection 实现。我的范围字段如下所示:
// Scopes ("rights") the Angular application wants get delegated
scope: 'openid profile email offline_access read:roles',
,但 access_token
永远不会包含超出 openid profile email offline_access
的范围。 IE。不会向应用授予 read:roles
的范围/权限,从而导致 Auth0 角色 API 失败。
解决方法
只是为了回答我自己的问题。这是一个与前端无关的错误。 Auth0 故意只允许前端具有有限的范围:https://auth0.com/docs/tokens/management-api-access-tokens/get-management-api-tokens-for-single-page-applications
^ 如果使用 Auth0,获得这些范围的唯一方法是包装您自己的 API,并在幕后使用秘密客户端 ID。这不是前端相关的问题。然后,根据授予后端 API 的权限,您或许可以通过后端获取自定义范围。