[英]React Native Expo. Azure auth
I created a React Native Expo project with Azure AD authentication according to this tutorial .我根据本教程创建了一个带有 Azure AD 身份验证的 React Native Expo 项目。
Here is my code:这是我的代码:
const discovery = useAutoDiscovery('https://login.microsoft.com/c764ad56-5d28-4d02-acc3-197e61278bb3');
const [request, response, promptAsync] = useAuthRequest (
{
clientId: '4344ecc3-5737-4aa0-b71c-2e65affb802c',
scopes: [ 'User.Read' ],
redirectUri: 'exp://192.168.1.7:19000'
},
discovery
);
const logon = async () => {
await promptAsync();
if (response.type == 'success') {
navigation.navigate('List');
}
}
I logged my request to the console exmin my login url我将我的请求记录到控制台 exmin 我的登录信息 url
AuthRequest {
"clientId": "4344ecc3-5737-4aa0-b71c-2e65affb802c",
"clientSecret": undefined,
"codeChallenge": "h5gKD7BtEXFtvWjP6ajKfNR4csomtPVtj-sRv5Zykn8",
"codeChallengeMethod": "S256",
"codeVerifier": "bCPan6PJWKmf0gLRZLKxK54DTSk402iQftTdFpHx1n7Xq9dX9CYF2fGDmvTjs6SopOho0i8BB70Usfi0M7ezws1a1GMWS0uv9T7ji9l4gv5jza11lJIk3Uil21xjUGh2",
"extraParams": Object {},
"prompt": undefined,
"redirectUri": "exp://192.168.1.7:19000",
"responseType": "code",
"scopes": Array [
"User.Read",
],
"state": "4cYI6HmNca",
"url": "https://login.microsoft.com/c764ad56-5d28-4d02-acc3-197e61278bb3/oauth2/authorize?code_challenge=h5gKD7BtEXFtvWjP6ajKfNR4csomtPVtj-sRv5Zykn8&code_challenge_method=S256&redirect_uri=exp%3A%2F%2F192.168.1.7%3A19000&client_id=4344ecc3-5737-4aa0-b71c-2e65affb802c&response_type=code&state=4cYI6HmNca&scope=User.Read",
"usePKCE": true,
}
Here is my Azure Ad registration data这是我的 Azure 广告注册数据
My redirect url is exp://192.168.1.7:19000我的重定向 url 是 exp://192.168.1.7:19000
And despite this, I get the error尽管如此,我还是得到了错误
The provided value for the input parameter 'redirect_uri' is not valid.
为输入参数“redirect_uri”提供的值无效。 The expected value is a URI which matches a redirect URI registered for this client application
预期值是一个 URI,它与为此客户端应用程序注册的重定向 URI 相匹配
What am I doing wrong?我究竟做错了什么?
Please check if below points are of any cause for the issue: .请检查以下几点是否是导致问题的原因: 。
for expo go redirect uri exp://localhost:19000/--/对于 expo go 重定向 uri exp://localhost:19000/--/
Also see uris according to the documentation provided > Authentication - Expo Documentation另请根据提供的文档查看 uris >身份验证 - Expo 文档
const discovery = useAutoDiscovery('https://login.microsoftonline.com/<TENANT_ID>/v2.0');
const discovery = useAutoDiscovery('https://login.microsoftonline.com/<TENANT_ID>/v2.0');
CODE代码
const discovery = useAutoDiscovery('https://login.microsoft.com/c764ad56-5d28-4d02-acc3-197e61278bb3/v2.0'); const [request, response, promptAsync] = useAuthRequest ( { clientId: '4344ecc3-5737-4aa0-b71c-2e65affb802c', redirectUri: AuthSession.makeRedirectUri({ native: "exp://localhost:19000", }), extraParams: { code_verifier: request.codeVerifier }, scopes: [ 'User.Read' ], // // }, discovery
AuthSession.makeRedirectUri does a lot of the heavy lifting involved with universal platform support.
AuthSession.makeRedirectUri 做了很多涉及通用平台支持的繁重工作。 Behind the scenes it uses expo-linking.
在幕后,它使用 expo-linking。
Build requests using AuthSession.useAuthRequest(), the hook allows for async setup which means mobile browsers won't block the authentication.
使用 AuthSession.useAuthRequest() 构建请求,钩子允许异步设置,这意味着移动浏览器不会阻止身份验证。
Reference : AuthSession not working for Authorization Code Flow参考: AuthSession 不适用于授权代码流
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.