我有以下KeyCloak客户端配置,以使用pkce身份验证流程:
Realm: REALM
Client ID: pkce-client
Client Protocol: openid-connect
Access Type: public
Standard Flow Enabled: ON
Valid Redirect URIs: http://localhost:4200/
Advanced Settings:
Proof Key for Code Exchange Code Challenge Method: S256我尝试通过openid_client https://pub.dev/packages/openid_client使用iOS模拟器在flutter应用程序中进行身份验证,如下所示
authenticate() async {
var uri = Uri.parse('http://$localhost:8180/auth/realms/REALM');
var clientId = 'pkce-client';
var scopes = List<String>.of(['profile', 'openid']);
var port = 4200;
var redirectUri = Uri.parse(http://localhost:4200/);
var issuer = await Issuer.discover(uri);
var client = new Client(issuer, clientId);
urlLauncher(String url) async {
if (await canLaunch(url)) {
await launch(url, forceWebView: true);
} else {
throw 'Could not launch $url';
}
}
var authenticator = new Authenticator(
client,
scopes: scopes,
port: port,
urlLancher: urlLauncher,
redirectUri: redirectUri,
);
var auth = await authenticator.authorize();
var token= await auth.getTokenResponse();
return token;
}但它只给我提供了这样的web视图:

运行KeyCloak的终端显示以下代码行:
INFO [org.keycloak.protocol.oidc.endpoints.AuthorizationEndpointChecker] (default task-34) PKCE enforced Client without code challenge method.
WARN [org.keycloak.events] (default task-34) type=LOGIN_ERROR, realmId=REALM, clientId=pkce-client, userId=null, ipAddress=127.0.0.1, error=invalid_request, response_type=code, redirect_uri=http://localhost:4200/, response_mode=query 当使用Postman时,它起作用了,并为我提供了登录页面:

但我在那里有额外的参数,当使用openid_client时,我不知道将它们添加到Authenticator(..)中的什么地方,状态会自动添加。
state: <state>
code_challenge: <code-challenge>
code_challenge_method: S256 我需要在openid_client方法中的某个地方添加这些code_challenge参数吗?
或者在使用App时需要更改重定向URL?我尝试了像这里提议的(https://githubmemory.com/repo/appsup-dart/openid_client/issues/32)那样的package_name,但也不起作用。
发布于 2021-11-09 06:44:44
: flow = redirectUri == null
? Flow.authorizationCodeWithPKCE(client)
: Flow.authorizationCode(client)您已经指定了redirectUri,所以使用了authorizationCode flow。但在这种情况下,您需要authorizationCodeWithPKCE flow。所以只需确保redirectUri为空,并且将使用正确的PKCE流(具有正确的url参数,例如code_challenge)。
https://stackoverflow.com/questions/69889165
复制相似问题