在 Expo 应用中使用 Auth0 获取 id_token
Getting an id_token using Auth0 in Expo app
我正在一个新的 Expo/React 本机应用程序中实施 Auth0 身份验证,遵循以下示例:
https://github.com/expo/auth0-example
我唯一更改的是 scope: 'openid profile'
,在示例中是 scope: 'openid name'
,尽管我也尝试使用示例中的代码。
正如您在下面的屏幕截图中看到的,我得到的是 access_token
而不是 id_token
:
这是使用 Auth0 进行身份验证的代码:
_loginWithAuth0 = async () => {
const redirectUrl = AuthSession.getRedirectUrl();
console.log(`Redirect URL (add this to Auth0): ${redirectUrl}`);
const result = await AuthSession.startAsync({
authUrl: `${auth0Domain}/authorize` + toQueryString({
client_id: auth0ClientId,
response_type: 'token',
scope: 'openid profile',
redirect_uri: redirectUrl,
}),
});
console.log(result);
if (result.type === 'success') {
this.handleParams(result.params);
}
}
我尝试将 response_type
更改为 token id_token
但抛出了一个错误提示配置错误。
如何获得 id_token
?
返回的令牌由 response_type
定义,而不是 scope
。对于 ID 令牌,作用域决定了令牌中返回的内容。你需要 response_type: 'id_token'
.
您可以在此处阅读有关其工作原理的更多信息:https://auth0.com/docs/tokens/id-token#control-the-contents-of-an-id-token
完全公开,我为 Auth0 工作。
我正在一个新的 Expo/React 本机应用程序中实施 Auth0 身份验证,遵循以下示例: https://github.com/expo/auth0-example
我唯一更改的是 scope: 'openid profile'
,在示例中是 scope: 'openid name'
,尽管我也尝试使用示例中的代码。
正如您在下面的屏幕截图中看到的,我得到的是 access_token
而不是 id_token
:
这是使用 Auth0 进行身份验证的代码:
_loginWithAuth0 = async () => {
const redirectUrl = AuthSession.getRedirectUrl();
console.log(`Redirect URL (add this to Auth0): ${redirectUrl}`);
const result = await AuthSession.startAsync({
authUrl: `${auth0Domain}/authorize` + toQueryString({
client_id: auth0ClientId,
response_type: 'token',
scope: 'openid profile',
redirect_uri: redirectUrl,
}),
});
console.log(result);
if (result.type === 'success') {
this.handleParams(result.params);
}
}
我尝试将 response_type
更改为 token id_token
但抛出了一个错误提示配置错误。
如何获得 id_token
?
返回的令牌由 response_type
定义,而不是 scope
。对于 ID 令牌,作用域决定了令牌中返回的内容。你需要 response_type: 'id_token'
.
您可以在此处阅读有关其工作原理的更多信息:https://auth0.com/docs/tokens/id-token#control-the-contents-of-an-id-token
完全公开,我为 Auth0 工作。