azure - 无法在 Expo 上使用 React Native 获取刷新令牌,并使用带有 PKCE 的授权代码流向 Microsoft Azure 进行身份验证
问题描述
谁能得到这个工作?可以取回访问令牌,但不能取回刷新令牌。这是一个使用 React Native 和 Expo 构建的移动应用程序。它使用 Microsoft Azure 进行身份验证,并使用带有 PKCE 的授权代码流。
这是我尝试过的代码:-
// Endpoint
const discovery = useAutoDiscovery('https://login.microsoftonline.com/TENNANT_ID/v2.0');
// Request
const [request, response, promptAsync] = useAuthRequest(
{
clientId: 'YOUR - CLIENT - ID',
scopes: ['openid', 'profile', 'email', 'offline_access'],
redirectUri: makeRedirectUri({
scheme: 'exp://YOUR IP ADDRESS:19000'
}),
// codeChallenge: 'CODE_CHALLENGE',
// codeChallengeMethod: 'S256',
// usePKCE: true
},
discovery
);
React.useEffect(() => {
if (response && 'params' in response) {
if (response.params && 'code' in response.params) {
(async function getToken() {
console.log('-----------------------')
console.log(response.params.code)
console.log('-----------------------')
try {
// @ts-ignore
const { accessToken } = await exchangeCodeAsync({
code: response.params.code,
clientId: 'YOUR - CLIENT - ID',
redirectUri: makeRedirectUri({
scheme: 'exp://YOUR IP ADDRESS:19000'
}),
scopes: ['openid', 'profile', 'email', 'offline_access'],
grant_type: "authorization_code",
extraParams: {
// code_verifier: "CODE_VERIFIER",
code_verifier: request?.codeVerifier || '' ,
},
}, {
tokenEndpoint: 'https://login.microsoftonline.com/TENNANT_ID/oauth2/v2.0/token' //
})
console.log('------- Access ----------------')
console.log(accessToken)
console.log('-----------------------')
解决方案
推荐阅读
- angular - Angular 9 - mat-select 的问题,它没有选择选项列表中的当前值
- c# - 我可以在 UWP 应用程序中导入和显示 3D 文件(例如从 Blender 导出)吗?
- javascript - 如何从javascript中的xml响应正文中读取字符串
- angular - 显示模态如果条件在Angular中为真?
- android - 为什么 Android 共享首选项的文件名需要唯一?
- c# - 自定义构造函数输入到 AutoFixture 中的抽象类
- c++ - 处理数组时指针中的分段错误
- autodesk-forge - 与剖面交互
- azure - 将 Azure Notebook 连接到 Azure VM
- sql - 仅显示每月至少有一个条目的用户