首页 > 解决方案 > 如何将 Expo AppAuth 模块与 IdentityServer4 一起使用

问题描述

我正在尝试使用 Expo AppAuth 模块在本机反应中使用 IdentityServer4 进行身份验证。似乎无法正确设置 redirectUri。当我重定向到 identityServer 时,我收到“无效的重定向 uri”错误。

这是我在身份服务器上的客户

return new List<Client>
            {
                new Client
                {
                    ClientName = "client",
                    ClientId = "client",
                    RequirePkce = true,
                    AllowedGrantTypes = GrantTypes.Code,
                    RequireClientSecret = false,
                    RequireConsent = true,
                    RedirectUris =
                    {
                        "host.exp.Exponent" //Is this correct
                    },
                    AllowOfflineAccess = true,
                    RefreshTokenUsage = TokenUsage.ReUse,
                    AllowedScopes = { "openid", "profile"},

                }
            };

我对 AppAuth 的配置设置是

const config = {
    issuer: 'http://localhost:3000',
    clientId: 'client',
    scopes: ['profile', 'openid'],
    redirectUri: "host.exp.Exponent"
}

标签: react-nativeidentityserver4expoappauth

解决方案


您应该指定redirectUri为地址值。

AppAuth 定义:

async function _executeAsync(props: OAuthProps): Promise<TokenResponse> {
  if (!props.redirectUrl) {
    props.redirectUrl = getDefaultOAuthRedirect();
  }
  assertValidProps(props);
  return await ExpoAppAuth.executeAsync(props);
}

export function getDefaultOAuthRedirect(): string {
  return `${ExpoAppAuth.OAuthRedirect}:/oauthredirect`;
}

推荐阅读