flutter_appauth:什么是正确的redirect_uri?

时间:2020-09-09 16:08:12

标签: flutter appauth

如果我在这里做错了什么,请纠正我。我有一个IdentityServer4(这是.NET的OIDC实现),并且客户端的定义如下:

new Client
{
    ClientId = "flutterclient",
    AllowedGrantTypes = GrantTypes.Code,
    ClientSecrets = new List<Secret> { new Secret("fluttersecret".Sha256()) },
    AllowedScopes = new List<string>
    {
        IdentityServerConstants.StandardScopes.OpenId,
        IdentityServerConstants.StandardScopes.Profile,
    },
    RedirectUris = { "com.example.flutter_client://oidccallback" },  // Is this correct?
    AllowOfflineAccess = true,
}

我目前正在尝试使用仿真器,我可以通过电话https://10.0.2.2:5001/.well-known/openid-configuration访问发现文档,因此我确定仿真器可以与我的IDP对话。

现在,我不太确定需要在flutter_appauth中输入什么参数:

// The flutter's code, trying to sign in
final AuthorizationTokenResponse result = await _appAuth.authorizeAndExchangeCode(
  AuthorizationTokenRequest(
    'flutterclient',
    '????',    // What should I put here as redirect URI?
    clientSecret: 'fluttersecret',
    serviceConfiguration: AuthorizationServiceConfiguration('https://10.0.2.2:5001/connect/authorize', 'https://10.0.2.2:5001/connect/token'),
    scopes: <String>['openid', 'profile'],
    preferEphemeralSession: false,
  ),
);

// The gradle's definition
defaultConfig {
    applicationId "com.example.flutter_client"
    minSdkVersion 18
    targetSdkVersion 28
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
    manifestPlaceholders = [
        'appAuthRedirectScheme': '10.0.2.2:5001'  // Is this correct?
    ]
}

特别是在与AuthorizationTokenRequest的'redirect_uri'参数斗争时,我尝试了'https://10.0.2.2:5001:/oauthredirect'、'10.0.2.2:5001:/oauthredirect',并且每次IDP都会告诉我有一个格式错误的redirect_uri。什么是正确的?我的其他参数正确吗?

2 个答案:

答案 0 :(得分:0)

“ appAuthRedirectScheme”由开发人员自己定义。定义后,只需在IS4的Client.RedirectUris上使用相同的值即可。

答案 1 :(得分:0)

  1. 确保您的 applicationId 和 appAuthRedirectScheme 不包含“_”或大写字符。
  2. 确保您的应用程序包名称在身份服务器 com.appname.xyz://login-callback 中相同,注意 ://login-callback
  3. 在 appAuthRedirectScheme 中只输入 applicationId,没有://login-callback。

代码的其他部分保持不变。