默认情况下,AppAuth在身份验证请求上发送S256
PKCE代码质询。如果需要与仅支持plain
代码质询方法的服务器进行互操作,如何配置授权请求?
最佳答案
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();