casdoor / casdoor-flutter-sdk

Flutter SDK for Casdoor, see example at: https://github.com/casdoor/casdoor-flutter-example
https://github.com/casdoor/casdoor
Apache License 2.0
12 stars 13 forks source link

Problem with refreshToken method #28

Closed Deltenman closed 1 year ago

Deltenman commented 1 year ago

When I try to refresh token with method

  Future<http.Response> refreshToken(String refreshToken, String? clientSecret,
      {String scope = "read"}) async {
    return await http.post(
        Uri(
          scheme: parseScheme(),
          host: parseHost(),
          port: parsePort(),
          path: "api/login/oauth/refresh_token",
        ),
        body: {
          'grant_type': 'authorization_code',
          'refresh_token': refreshToken,
          'scope': scope,
          'client_id': config.clientId,
          'client_secret': clientSecret
        });
  }

, I never get answer with the new token. Tried with/without clientSecret, tried with access/refresh/auth tokens (because thought that have incorrect variable for token) -- no luck. But if I try to do this request manually

final response = await http.post(
    Uri(
      scheme: "https",
      host: dotenv.get('CASDOOR_ENDPOINT').split("//").last,
      port: 443,
      path: "api/login/oauth/refresh_token",
    ),
    body: {
      'grant_type': 'refresh_token',
      'refresh_token': data.token.refreshToken,
      'scope': "read",
      'client_id': dotenv.get('CASDOOR_CLIENT_ID'),
      'client_secret': dotenv.get('CASDOOR_CLIENT_SECRET'),
    });

, I get the new token. What problem could be in library's method?

casbin-bot commented 1 year ago

@seriouszyx @ComradeProgrammer @Resulte

hsluoyz commented 1 year ago

@Deltenman what's the difference between the two requests? What's the key point you want to specify here?

Deltenman commented 1 year ago

@hsluoyz another grand_type: I using 'grant_type': 'refresh_token', in your method it's 'grant_type': 'authorization_code',

hsluoyz commented 1 year ago

@Deltenman can you make a PR to fix it?

Deltenman commented 1 year ago

@hsluoyz https://github.com/casdoor/casdoor-flutter-sdk/pull/31