【问题标题】:How can I use the "plain" PKCE code challenge method with AppAuth?如何在 AppAuth 中使用“普通”PKCE 代码质询方法?
【发布时间】:2016-06-04 15:02:13
【问题描述】:

默认情况下,AppAuth 在身份验证请求上发送S256 PKCE 代码质询。如果我需要与只支持plain代码质询方式的服务器互操作,我该如何配置我的授权请求?

【问题讨论】:

    标签: android ios appauth pkce


    【解决方案1】:

    iOS:您可以使用OIDAuthorizationRequest initWithConfiguration:clientId:scope:redirectURL:responseType:state:codeVerifier:codeChallenge:codeChallengeMethod:additionalParameters: 构造函数覆盖PKCE 参数。这可用于发送自定义PKCE方法(该库仅支持S256)。

    // builds authentication request
    NSString *codeVerifier = [OIDAuthorizationRequest generateCodeVerifier];
    OIDAuthorizationRequest *request =
        [[OIDAuthorizationRequest alloc] initWithConfiguration:configuration
                        clientId:kClientID
                          scope:@"openid profile"
                     redirectURL:redirectURI
                    responseType:OIDResponseTypeCode
                           state:[OIDAuthorizationRequest generateState]
                    codeVerifier:codeVerifier
                   codeChallenge:codeVerifier
             codeChallengeMethod:@"plain"
            additionalParameters:nil];
    

    Android:您可以通过将setCodeVerifier(String, String, String) 添加到您的构建器来覆盖PKCE 参数。这可用于发送自定义 PKCE 方法(默认情况下,库在支持 SHA-256 平台的客户端上使用 S256)。

    import net.openid.appauth.CodeVerifierUtil;
    
    String codeVerifier = CodeVerifierUtil.generateRandomCodeVerifier();
    AuthorizationRequest authRequest = new AuthorizationRequest.Builder(
        serviceConfig,
        CLIENT_ID,
        AuthorizationRequest.RESPONSE_TYPE_CODE,
        REDIRECT_URI)
        .setScope(SCOPE)
        .setCodeVerifier(codeVerifier, codeVerifier, "plain")
        .build();
    

    【讨论】:

      猜你喜欢
      • 2021-10-15
      • 2013-10-11
      • 1970-01-01
      • 2020-11-28
      • 2021-03-18
      • 1970-01-01
      • 2013-07-31
      • 2020-11-19
      • 2020-05-03
      相关资源
      最近更新 更多