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

Add OAuth2 JWT bearer grant type support for client #588

Merged
merged 4 commits into from
Aug 17, 2021

Conversation

ldclakmal
Copy link
Member

@ldclakmal ldclakmal commented Aug 17, 2021

Purpose

This PR adds OAuth2 JWT bearer grant type support for HTTP client.

Fixes: ballerina-platform/ballerina-library#1788

Examples

import ballerina/http;
import ballerina/io;

http:Client securedEP = check new("https://localhost:9090",
    auth = {
        tokenUrl: "https://localhost:9445/oauth2/token",
        assertion: "eyJhbGciOiJFUzI1NiIsImtpZCI6Ij[...omitted for brevity...]",
        clientId: "FlfJYKBD2c925h4lkycqNZlC2l4a",
        clientSecret: "PJz0UhTJMrHOo68QQNpvnqAY_3Aa",
        scopes: ["admin"],
        clientConfig: {
            secureSocket: {
                cert: "../resource/path/to/public.crt"
            }
        }
    },
    secureSocket = {
        cert: "../resource/path/to/public.crt"
    }
);

public function main() returns error? {
    string response = check securedEP->get("/foo/bar");
    io:println(response);
}

Checklist

  • Linked to an issue
  • Updated the changelog
  • Added tests

shafreenAnfar
shafreenAnfar previously approved these changes Aug 17, 2021
@codecov
Copy link

codecov bot commented Aug 17, 2021

Codecov Report

Merging #588 (f6bca0d) into master (aa4002f) will increase coverage by 0.15%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #588      +/-   ##
============================================
+ Coverage     80.13%   80.28%   +0.15%     
  Complexity       67       67              
============================================
  Files           335      335              
  Lines         17081    17082       +1     
  Branches       3816     3816              
============================================
+ Hits          13688    13715      +27     
+ Misses         2651     2630      -21     
+ Partials        742      737       -5     
Impacted Files Coverage Δ
ballerina/auth_types.bal 100.00% <100.00%> (ø)
...transport/message/Http2InboundContentListener.java 51.28% <0.00%> (-2.57%) ⬇️
...tdlib/http/transport/contractimpl/common/Util.java 83.03% <0.00%> (ø)
...ib/http/api/client/actions/AbstractHTTPAction.java 67.46% <0.00%> (+0.80%) ⬆️
...nsport/contractimpl/DefaultHttpResponseFuture.java 74.67% <0.00%> (+1.94%) ⬆️
...dlib/http/transport/message/HttpCarbonMessage.java 95.08% <0.00%> (+2.18%) ⬆️
...ttp/transport/message/HttpMessageDataStreamer.java 89.77% <0.00%> (+2.27%) ⬆️
...ransport/message/DefaultFullHttpMessageFuture.java 100.00% <0.00%> (+4.00%) ⬆️
...contractimpl/listener/states/ReceivingHeaders.java 53.06% <0.00%> (+4.08%) ⬆️
...a/stdlib/http/transport/message/MessageFuture.java 95.65% <0.00%> (+4.34%) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update aa4002f...f6bca0d. Read the comment docs.

@ldclakmal ldclakmal merged commit 389a5b8 into ballerina-platform:master Aug 17, 2021
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 this pull request may close these issues.

Extend client OAuth2 grant types support for JWT bearer grant type
3 participants