angular - 自定义范围:将 angular-oauth2-oidc 与 Auth0 和 Github 一起使用
问题描述
我正在尝试将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 应用程序所需的范围。
如果这个问题不够清楚,请随时发表评论,并将整理问题。
解决方案
只是为了回答我自己的问题。这是一个与前端无关的错误。Auth0 故意只允许前端具有有限的范围:https ://auth0.com/docs/tokens/management-api-access-tokens/get-management-api-tokens-for-single-page-applications
^ 如果使用 Auth0,获取这些范围的唯一方法是包装您自己的 API,并在幕后使用秘密客户端 ID。这不是前端相关的问题。然后根据授予后端 API 的权限,您可能能够通过后端获取自定义范围。
推荐阅读
- android - Android 7.0 上的 ADB 和 root 访问
- css - 更改所选文本的样式/格式 - Angular
- c# - 表单的设计 - 未注册类(HRESULT 异常:0x80040154 (REGDB_E_CLASSNOTREG))
- html - HTML问题/通过Powershell激活
- sql - 如何按另一列按顺序选择分组中的第一个值
- python - tk 窗口不加载
- r - 如何在 RMarkdown 中生成带有标题的分页表?
- javascript - MaterializeCSS 模态事件未触发
- jenkins - Kubernetes 在版本“extensions/v1beta1”中没有匹配类型“部署”
- java - java中1到100之间的素数