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 #292

Merged
merged 2 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 WebSocket client.

Fixes: ballerina-platform/ballerina-library#1788

Examples

import ballerina/io;
import ballerina/websocket;

websocket:Client securedEP = check new("wss://localhost:9090/foo/bar",
    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? {
    check securedEP->writeTextMessage("Hello, World!");
    string textMessage = check securedEP->readTextMessage();
    io:println(textMessage);
}

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 #292 (5f38289) into main (9f6b682) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##               main     #292   +/-   ##
=========================================
  Coverage     81.37%   81.38%           
  Complexity      351      351           
=========================================
  Files            43       43           
  Lines          2051     2052    +1     
  Branches        318      318           
=========================================
+ Hits           1669     1670    +1     
  Misses          296      296           
  Partials         86       86           
Impacted Files Coverage Δ
ballerina/auth_types.bal 88.23% <100.00%> (+0.73%) ⬆️

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 9f6b682...5f38289. Read the comment docs.

@ldclakmal ldclakmal merged commit f1a8667 into ballerina-platform:main 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