Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting basicAuth: false when doing a refresh() #24

Closed
dJani97 opened this issue Sep 9, 2024 · 1 comment · Fixed by #25
Closed

Allow setting basicAuth: false when doing a refresh() #24

dJani97 opened this issue Sep 9, 2024 · 1 comment · Fixed by #25

Comments

@dJani97
Copy link

dJani97 commented Sep 9, 2024

The default code for OAuthChopper.refresh() calls oauth2.Credentials.refresh() with these parameters:

final newCredentials = await credentials.refresh(
  identifier: identifier,
  secret: secret,
  httpClient: httpClient,
);

In my use-case, the default bool basicAuth = true parameter causes a problem, because AWS Cognito refuses such requests with a 400 { "error": "invalid_client" } code. See source.

I would suggest extending the OAuthChopper.refresh() method to include all optional parameters of the wrapped oauth2.Credentials.refresh() method:

Future<OAuthToken?> refresh({bool basicAuth = true, Iterable<String>? newScopes}) async {
  final credentialsJson = await _storage.fetchCredentials();
  if (credentialsJson == null) return null;
  final credentials = oauth2.Credentials.fromJson(credentialsJson);
  try {
    final newCredentials = await credentials.refresh(
      identifier: identifier,
      secret: secret,
      httpClient: httpClient,
      basicAuth: basicAuth,
      newScopes: newScopes,
    );
    await _storage.saveCredentials(newCredentials.toJson());
    return OAuthToken.fromCredentials(newCredentials);
  } on oauth2.AuthorizationException {
    _storage.clear();
    rethrow;
  }
}
@Guldem
Copy link
Collaborator

Guldem commented Sep 10, 2024

Thanks for the feedback! Initially I only implemented the parameters needed for our own use-cases.

I have extended oauth_chopper to support more of the auth2 package parameters in #25. Including the extra refresh parameters. Hopefully this solves your problem.

When its merged I will publish the package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants