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

JDK11 HTTP client used for OAuth2 authorization endpoint should support OAuth2 client authentication #935

Closed
ldclakmal opened this issue Feb 5, 2021 · 1 comment · Fixed by ballerina-platform/module-ballerina-oauth2#96
Assignees
Labels
Area/Security Issues related to stdlib security module/jwt module/oauth2 Team/PCM Protocol connector packages related issues Type/Improvement

Comments

@ldclakmal
Copy link
Member

ldclakmal commented Feb 5, 2021

Description
The JDK11 HTTP client implementation which is used in oauth2 module in order to send requests to 'authorization server', should support OAuth2 client authentication mechanisms. This support is provided for Ballerina 1.2.x versions but it was removed since the client implementation is moved from Ballerina to JDK11 HTTP client.

@ldclakmal
Copy link
Member Author

ldclakmal commented Feb 23, 2021

The client of oauth2 module can only be provided OAuth2 grant types supported by Ballerina. Because with the introduction of other auth schemes, there will be cyclic dependency issues. Same applies for jwt module client as well.

Sample implementation for oauth2 module:

public type ClientConfiguration record {|
    HttpVersion httpVersion = HTTP_1_1;
    map<string> customHeaders?;
    string customPayload?;
    ClientAuth auth?;
    SecureSocket secureSocket?;
|};

public type ClientAuth ClientCredentialsGrantConfig|PasswordGrantConfig|DirectTokenConfig;

public class ListenerOAuth2Provider {

    public isolated function init(IntrospectionConfig introspectionConfig) {
        // ...
        ClientAuth? auth = introspectionConfig.clientConfig?.auth;
        if (auth is ClientAuth) {
            ClientOAuth2Provider clientOAuth2Provider = new(auth);
            string|Error accessToken = clientOAuth2Provider.generateToken();
            if (accessToken is string) {
                map<string>? customHeadersMap = introspectionConfig.clientConfig?.customHeaders;
                if (customHeadersMap is map<string>) {
                    customHeadersMap["Authorization"] = "Bearer " + accessToken;
                } else {
                    introspectionConfig.clientConfig.customHeaders = { "Authorization" : "Bearer " + accessToken };
                }
            }
        }
    }
// ...
}

@ldclakmal ldclakmal changed the title JDK11 HTTP client used for auth modules should support client authentication JDK11 HTTP client used for OAuth2 introspection should support OAuth2 client authentication Feb 25, 2021
@ldclakmal ldclakmal added this to the Swan Lake Alpha3 milestone Mar 1, 2021
@anupama-pathirage anupama-pathirage added the Team/PCM Protocol connector packages related issues label Mar 1, 2021
@ldclakmal ldclakmal changed the title JDK11 HTTP client used for OAuth2 introspection should support OAuth2 client authentication JDK11 HTTP client used for OAuth2 authorization endpoint should support OAuth2 client authentication Mar 11, 2021
@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/jwt module/oauth2 Team/PCM Protocol connector packages related issues Type/Improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants