根据本教程的说法,我创建了一个带有Azure认证的React本地世博会项目。
这是我的代码:
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');
}
}我将请求记录到控制台(除登录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,
}这是我的Azure广告注册数据

我的重定向网址是exp://192.168.1.7:19000
尽管如此,我还是发现了错误
输入参数'redirect_uri‘提供的值无效。期望值是一个URI,它与为此客户端应用程序注册的重定向URI相匹配。
我做错了什么?
发布于 2021-09-27 11:56:29
请查核以下各点是否有任何问题的原因:
对于世博会,请重定向uri exp://localhost:19000/-/
还请参见根据所提供的文档> 认证-世博文件编写的uris
康斯特发现= useAutoDiscovery('https://login.microsoftonline.com//v2.0');
码
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做了很多与通用平台支持相关的繁重工作。它在幕后使用世博会链接。 使用AuthSession.useAuthRequest()构建请求,钩子允许异步设置,这意味着移动浏览器不会阻止身份验证。
https://stackoverflow.com/questions/69336253
复制相似问题