【发布时间】:2021-12-21 15:05:49
【问题描述】:
我有以下 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 在带有 iOS 模拟器的颤振应用程序中进行身份验证 https://pub.dev/packages/openid_client这样的
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;
}
运行 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 时,它可以工作,它为我提供了登录页面:
但是我那里有额外的参数,不知道在Authenticator(..)哪里添加,使用openid_client时,状态会自动添加。
state: <state>
code_challenge: <code-challenge>
code_challenge_method: S256
我需要在 openid_client 方法的某处添加这些 code_challenge 参数吗?
或者我在使用应用程序时是否需要更改重定向 URL?我尝试使用此处建议的 package_name (https://githubmemory.com/repo/appsup-dart/openid_client/issues/32),但它也不起作用。
【问题讨论】:
标签: flutter keycloak openid-connect pkce