簡體   English   中英

使用openid_client通過帶有keycloak的pkce flutter應用程序進行身份驗證后如何獲取刷新令牌?

[英]How to get refresh token after authenticate via pkce flutter app with keycloak using openid_client?

我有以下 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

當使用 iOS 模擬器通過 openid_client https://pub.dev/packages/openid_client使用 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 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,
    );

    var auth = await authenticator.authorize();
    var token= await auth.getTokenResponse();
    return token;
  }

我得到以下回復: 在此處輸入圖像描述

如何使用刷新令牌獲取新的訪問令牌?

我試過了:

POST http://localhost:8180/auth/realms/REALM/protocol/openid-connect/token
Content-Type: application/x-www-form-urlencoded
client_id: pkce-client
grant_type: refresh_token
refresh_token: "received refresh token"

但我得到:

{"error":"invalid_client","error_description":"Invalid client credentials"}

我需要如何准備刷新訪問令牌的請求?

提前致謝

問題的一個原因可能是您需要在請求中也包含client_secret 如果客戶端是“機密”客戶端,則可能需要這樣做。

請參閱此處的討論以獲取更多詳細信息。 通過 Keycloak 中的 refresh_token 刷新 access_token

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM