Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Authentication React Native Expo:使用Identity Server 4进行身份验证_Authentication_Expo_React Native Android_Identityserver4_Bearer Token - Fatal编程技术网

Authentication React Native Expo:使用Identity Server 4进行身份验证

Authentication React Native Expo:使用Identity Server 4进行身份验证,authentication,expo,react-native-android,identityserver4,bearer-token,Authentication,Expo,React Native Android,Identityserver4,Bearer Token,我正在尝试使用expo文档中的示例代码“https://docs.expo.io/guides/authentication/“用于标识服务器4。我已经从ASP.NET核心Web应用程序创建了一个React模板。当我运行react本机应用程序重定向到ASP应用程序的登录页面时,我可以登录,但问题是窗口没有关闭以返回令牌。它登录,然后我转到ASP应用程序的主页。我认为我丢失了重定向URL,或者客户端设置不正确。有人能帮我设置一下吗?或者我错过了什么 以下是从appsettings.json的ASP

我正在尝试使用expo文档中的示例代码“https://docs.expo.io/guides/authentication/“用于标识服务器4。我已经从ASP.NET核心Web应用程序创建了一个React模板。当我运行react本机应用程序重定向到ASP应用程序的登录页面时,我可以登录,但问题是窗口没有关闭以返回令牌。它登录,然后我转到ASP应用程序的主页。我认为我丢失了重定向URL,或者客户端设置不正确。有人能帮我设置一下吗?或者我错过了什么

以下是从appsettings.json的ASP应用程序设置的我的客户端:

"IdentityServer": {
    "Clients": {
      "AAA": {
        "ClientId": "myclientid,
        "ClientName": "Native Client (Code with PKCE)",
        "RequireClientSecret": false,
        "RedirectUris": [ "io.expo.auth/@username/Auth" ],
        "AllowedGrantTypes": "GrantTypes.Code",
        "RequirePkce": "true",
        "AllowedScopes": ['openid', 'profile', 'email', 'offline_access'],
        "AllowOfflineAccess": "true",
        "Profile": "IdentityServerSPA",
        "ClientSecrets": [
          {
            "Value": "secretvalue"
          }
        ]
      }
    },
    
下面是我的React原生应用程序:

import * as React from 'react';
import { Button, Text, View } from 'react-native';
import * as AuthSession from 'expo-auth-session';
import * as WebBrowser from 'expo-web-browser';

WebBrowser.maybeCompleteAuthSession();

const useProxy = true;

const redirectUri = AuthSession.makeRedirectUri({
  native: 'myApp://io.expo.auth/@username/Auth',
  useProxy,
});

export default function App() {
  const discovery = AuthSession.useAutoDiscovery('https://demo.identityserver.io');
  
  // Create and load an auth request
  const [request, result, promptAsync] = AuthSession.useAuthRequest(
    {
      clientId: 'myclientid',
      redirectUri,
      scopes: ['openid', 'profile', 'email', 'offline_access'],
    },
    discovery
  );

  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <Button title="Login!" disabled={!request} onPress={() => promptAsync({ useProxy })} />
      {result && <Text>{JSON.stringify(result, null, 2)}</Text>}
    </View>
  );
}
import*as React from'React';
从“react native”导入{按钮、文本、视图};
从“expo auth session”导入*作为AuthSession;
从“世博网络浏览器”导入*作为网络浏览器;
WebBrowser.maybeCompleteAuthSession();
const useProxy=true;
const redirectUri=AuthSession.makeRedirectUri({
本机:'myApp://io.expo.auth/@username/auth',
使用代理,
});
导出默认函数App(){
const discovery=AuthSession.useAutoDiscovery('https://demo.identityserver.io');
//创建并加载身份验证请求
const[request,result,promptAsync]=AuthSession.useAuthRequest(
{
clientId:'myclientid',
乌里,
作用域:['openid','profile','email','offline_access'],
},
发现
);
返回(
promptAsync({useProxy}}/>
{result&&{JSON.stringify(result,null,2)}
);
}

以下是您需要修复的代码:

  • 在appsettings.json上,将重定向URI更改为列表,结果如下:
  • 阅读更多

  • 确保
    RedirectUris
    上列出的URL存在,并且它与本机客户端上为
    redirectUri
    设置的值匹配。我不是世博会专家,你可以使用某种中间件,但据我所知,从你上面的代码来看,这些URL不匹配

  • @nahidf:我已经从react本机和ASP应用程序更新了url。在android应用程序上登录仍然可以,但在我登录后,该应用程序将保持打开状态,该ASP应用程序的主页不会关闭以返回react应用程序并返回令牌。因为我在本地运行世博会应用程序,所以必须发布它吗?另外,ASP我已经在本地服务器上发布了它。

    老实说,我不太确定从react本机中放入什么作为重定向URI。这就是为什么我没有匹配链接,并将它们保持原样。@Jack redirect url应该是``,在url中替换您的用户名和应用程序名-我建议您阅读-也避免更改问题,如果您只需要在底部添加更改,无需发布,只要react app中设置的url有效,就可以了,您编辑重定向URI后,它的值是多少?在RN上,我有这样一个:const redirectUri=AuthSession.makeRedirectUri({native:'myApp://io.expo.auth/@Ajack/auth',useProxy,});其中,“myApp”是app.json中的slug,“Auth”是scheme。在identity server中,我有:“重定向URI”:[“myApp://io.expo.auth/@Ajack/auth”],您是否在客户端和IdentityServer配置上都使用此URL?他们应该是全场比赛,他们都是比赛。有人有什么解决办法吗?谢谢
    "IdentityServer": {
        "Clients": {
          "AAA": {
            "ClientId": "myclientid,
            "ClientName": "Native Client (Code with PKCE)",
            "RequireClientSecret": false,
            "RedirectUris": [ "io.expo.auth/@username/Auth" ],
            "AllowedGrantTypes": "GrantTypes.Code",
            "RequirePkce": "true",
            "AllowedScopes": [ "api" ],
            "AllowOfflineAccess": "true",
            "Profile": "IdentityServerSPA",
            "ClientSecrets": [
              {
                "Value": "secretvalue"
              }
            ]
          }
        },