Search code examples
react-nativeidentityserver4expoappauth

How to use Expo AppAuth module with IdentityServer4


I am trying to use the Expo AppAuth module to do authentication using IdentityServer4 in react native. Cant seem to get the redirectUri settings right. I'm getting an 'invalid redirect uri" error when i redirect to identityServer.

This is my client on identityserver

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"},

                }
            };

My config settings for AppAuth are

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

Solution

  • You should specify redirectUri as the address value.

    AppAuth Definitions:

    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`;
    }