Last active
January 17, 2020 10:40
-
-
Save ldclakmal/47cb954a4ca1255569bd9ac9b0c540d6 to your computer and use it in GitHub Desktop.
Ballerina JWT authentication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
endpoint http:Client jwtAuthClient { | |
url: "https://www.example.org/api/v1", | |
auth: { | |
scheme: http:JWT_AUTH | |
} | |
}; | |
public function testJWTAuth() { | |
setJwtTokenToAuthContext(); | |
string requestPath = "/employees"; | |
var response = jwtClient->get(requestPath); | |
io:println(response); | |
} | |
function setJwtTokenToAuthContext() { | |
string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJiYWxsZXJ" + | |
"pbmEiLCJpc3MiOiJiYWxsZXJpbmEiLCJleHAiOjI4MTg0MTUwMTksImlhdCI6MTUyND" + | |
"U3NTAxOSwianRpIjoiZjVhZGVkNTA1ODVjNDZmMmI4Y2EyMzNkMGMyYTNjOWQiLCJhdW" + | |
"QiOlsiYmFsbGVyaW5hIiwiYmFsbGVyaW5hLm9yZyIsImJhbGxlcmluYS5pbyJdLCJzY" + | |
"29wZSI6ImhlbGxvIn0.bNoqz9_DzgeKSK6ru3DnKL7NiNbY32ksXPYrh6Jp0_O3ST7W" + | |
"fXMs9WVkx6Q2TiYukMAGrnMUFrJnrJvZwC3glAmRBrl4BYCbQ0c5mCbgM9qhhCjC1tB" + | |
"A50rjtLAtRW-JTRpCKS0B9_EmlVKfvXPKDLIpM5hnfhOin1R3lJCPspJ2ey_Ho6fDhs" + | |
"KE3DZgssvgPgI9PBItnkipQ3CqqXWhV-RFBkVBEGPDYXTUVGbXhdNOBSwKw5ZoVJrCU" + | |
"iNG5XD0K4sgN9udVTi3EMKNMnVQaq399k6RYPAy3vIhByS6QZtRjOG8X93WJw-9GLiH" + | |
"vcabuid80lnrs2-mAEcstgiHVw"; | |
runtime:getInvocationContext().authContext.scheme = "jwt"; | |
runtime:getInvocationContext().authContext.authToken = token; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment