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

oauth2:OutboundOAuth2Provider is not renewing access token when downstream web API returns 403 #17

Closed
madushajg opened this issue Jul 21, 2020 · 4 comments
Assignees
Labels
Area/Security Issues related to stdlib security module/oauth2 Type/Bug Verson/SwanLakeDump All issues planned for Swan Lake GA release

Comments

@madushajg
Copy link

madushajg commented Jul 21, 2020

Description:
We are using Azure log analytics REST API and authenticate requests using client_credentials grant type with https://login.microsoftonline.com as the token endpoint.
We noticed that Azure log analytics REST API returns an HTTP response with403 status code and the below payload when the token is expired.

{
    "error": {
        "message": "The provided authentication is not valid for this resource",
        "code": "InvalidTokenError",
        "innererror": {
            "code": "InvalidTokenError",
            "message": "Could not validate the request. Challenge failed: TokenExpired"
        }
    }
}

Due to this (not received 401 response), the oauth2:OutboundOAuth2Provider is not attempting to renew the token, instead uses the same expired token.

Affected Versions:
Ballerina Swan Lake Preview 2

@ldclakmal ldclakmal transferred this issue from ballerina-platform/ballerina-lang Sep 29, 2020
@ldclakmal ldclakmal transferred this issue from ballerina-platform/module-ballerina-oauth2 Oct 22, 2020
@ldclakmal ldclakmal changed the title http:BearerAuthHandler is not renewing access token when downstream web API returns 403 oauth2:OutboundOAuth2Provider is not renewing access token when downstream web API returns 403 Oct 27, 2020
@ldclakmal
Copy link
Member

ldclakmal commented Oct 27, 2020

@madushajg Shall we verify the issue with the attached .jar in SLP5?

ballerina-oauth2-1.0.1.jar.zip

DEBUG:
ballerina-oauth2-1.0.1.jar.zip

oauth2:ClientCredentialsGrantConfig config = {
    ...
    retryConfig: {
         statusCode: 403
    }
};
isolated function updateOAuth2CacheEntry(....) {
    ...
    if (expiresIn is int) {
        ....
    } else if (expiresIn is string) {
        oauth2CacheEntry.expTime = issueTime = (<int>expiresIn - clockSkewInSeconds) * 1000;
    }
}

@madushajg
Copy link
Author

madushajg commented Oct 27, 2020

Ack. Will verify with the provided jar.

@madushajg
Copy link
Author

@madushajg Shall we verify the issue with the attached .jar in SLP5?

ballerina-oauth2-1.0.1.jar.zip

@ldclakmal The issue is not there with the provided .jar

@ldclakmal
Copy link
Member

This issue is fixed with ballerina-platform/module-ballerina-http#142 and no longer valid with the new design.

@ldclakmal ldclakmal added the Area/Security Issues related to stdlib security label Sep 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/Security Issues related to stdlib security module/oauth2 Type/Bug Verson/SwanLakeDump All issues planned for Swan Lake GA release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants