Skip to content

Commit

Permalink
Merge pull request #13808 from ayomawdb/auth-refactoring-2019
Browse files Browse the repository at this point in the history
Reorganize and cleanup auth stdlib
  • Loading branch information
ayomawdb authored Feb 25, 2019
2 parents bc68994 + 5c581d9 commit ba6e2eb
Show file tree
Hide file tree
Showing 129 changed files with 3,197 additions and 2,496 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import ballerina/log;
http:Client httpEndpoint = new("https://localhost:9090", config = {
auth: {
scheme: http:BASIC_AUTH,
username: "tom",
password: "1234"
config: {
username: "tom",
password: "1234"
}
}
});

Expand All @@ -30,8 +32,8 @@ public function main() {

// Create a basic authentication provider with the relevant configurations.
http:AuthProvider basicAuthProvider = {
scheme: "basic",
authStoreProvider: "config"
scheme: http:BASIC_AUTH,
authStoreProvider: http:CONFIG_AUTH_STORE
};

listener http:Listener ep = new(9090, config = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public function main() {
"KE3DZgssvgPgI9PBItnkipQ3CqqXWhV-RFBkVBEGPDYXTUVGbXhdNOBSwKw5ZoVJrCU" +
"iNG5XD0K4sgN9udVTi3EMKNMnVQaq399k6RYPAy3vIhByS6QZtRjOG8X93WJw-9GLiH" +
"vcabuid80lnrs2-mAEcstgiHVw";
runtime:getInvocationContext().authContext.scheme = "jwt";
runtime:getInvocationContext().authContext.authToken = token;
runtime:getInvocationContext().authenticationContext.scheme = "jwt";
runtime:getInvocationContext().authenticationContext.authToken = token;

// Send a `GET` request to the specified endpoint.
var response = httpEndpoint->get("/hello/sayHello");
Expand All @@ -39,13 +39,15 @@ public function main() {

// Create a JWT authentication provider with the relevant configurations.
http:AuthProvider jwtAuthProvider = {
scheme: "jwt",
issuer: "ballerina",
audience: "ballerina.io",
certificateAlias: "ballerina",
trustStore: {
path: "${ballerina.home}/bre/security/ballerinaTruststore.p12",
password: "ballerina"
scheme: http:JWT_AUTH,
config: {
issuer: "ballerina",
audience: ["ballerina.io"],
certificateAlias: "ballerina",
trustStore: {
path: "${ballerina.home}/bre/security/ballerinaTruststore.p12",
password: "ballerina"
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import ballerina/log;
http:Client httpEndpoint = new("https://www.googleapis.com/tasks/v1", config = {
auth: {
scheme: http:OAUTH2,
accessToken: "ya29.GlufBimE7JZdiB_FpFtZn7p1WMtloVeMlqiYXDGF97068VvJCyK8rEFqBBkxT10E0qudipwxTjJTkU4we0hbOcHKjNTXz6JTEZYoRVn7F3-0O_bL9g71Rwek7TFI",
clientId: "833478926540-va43h2lhdhfc06i9eivlmaehl3o5uk1i.apps.googleusercontent.com",
clientSecret: "4ZsV4gwSuIoRdy6TKUXTanlw",
refreshToken: "1/XUtrd8DaeoopmX5xpIvGdXY09VAY6_h8fVVj9xCaKJE",
refreshUrl: "https://www.googleapis.com/oauth2/v4/token"
config: {
accessToken: "ya29.GlufBimE7JZdiB_FpFtZn7p1WMtloVeMlqiYXDGF97068VvJCyK8rEFqBBkxT10E0qudipwxTjJTkU4we0hbOcHKjNTXz6JTEZYoRVn7F3-0O_bL9g71Rwek7TFI",
clientId: "833478926540-va43h2lhdhfc06i9eivlmaehl3o5uk1i.apps.googleusercontent.com",
clientSecret: "4ZsV4gwSuIoRdy6TKUXTanlw",
refreshToken: "1/XUtrd8DaeoopmX5xpIvGdXY09VAY6_h8fVVj9xCaKJE",
refreshUrl: "https://www.googleapis.com/oauth2/v4/token"
}
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import ballerina/http;

http:AuthProvider basicAuthProvider = {
scheme: "basic",
authStoreProvider: "config"
scheme: http:BASIC_AUTH,
authStoreProvider: http:CONFIG_AUTH_STORE
};

// The endpoint used here is `http:Listener`, which by default tries to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ function testAuthSuccess() {
http:Client httpEndpoint = new("https://localhost:9090", config = {
auth: {
scheme: http:BASIC_AUTH,
username: "tom",
password: "password1"
config: {
username: "tom",
password: "password1"
}
}
});
// Send a `GET` request to the specified endpoint.
Expand All @@ -42,8 +44,10 @@ function testAuthnFailure() {
http:Client httpEndpoint = new("https://localhost:9090", config = {
auth: {
scheme: http:BASIC_AUTH,
username: "tom",
password: "password"
config: {
username: "tom",
password: "password"
}
}
});
// Send a `GET` request to the specified endpoint.
Expand All @@ -61,8 +65,10 @@ function testAuthzFailure() {
http:Client httpEndpoint = new("https://localhost:9090", config = {
auth: {
scheme: http:BASIC_AUTH,
username: "dick",
password: "password2"
config: {
username: "dick",
password: "password2"
}
}
});
// Send a `GET` request to the specified endpoint
Expand Down
16 changes: 9 additions & 7 deletions examples/secured-service-with-jwt/secured_service_with_jwt.bal
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import ballerina/http;
// Create a JWT authentication provider with the relevant configuration
// parameters.
http:AuthProvider jwtAuthProvider = {
scheme:"jwt",
issuer:"ballerina",
audience: "ballerina.io",
certificateAlias: "ballerina",
trustStore: {
path: "${ballerina.home}/bre/security/ballerinaTruststore.p12",
password: "ballerina"
scheme: http:JWT_AUTH,
config: {
issuer:"ballerina",
audience: ["ballerina.io"],
certificateAlias: "ballerina",
trustStore: {
path: "${ballerina.home}/bre/security/ballerinaTruststore.p12",
password: "ballerina"
}
}
};
// The endpoint used here is `http:Listener`. The JWT authentication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ function setJwtTokenToAuthContext () {
"KE3DZgssvgPgI9PBItnkipQ3CqqXWhV-RFBkVBEGPDYXTUVGbXhdNOBSwKw5ZoVJrCU" +
"iNG5XD0K4sgN9udVTi3EMKNMnVQaq399k6RYPAy3vIhByS6QZtRjOG8X93WJw-9GLiH" +
"vcabuid80lnrs2-mAEcstgiHVw";
runtime:getInvocationContext().authContext.scheme = "jwt";
runtime:getInvocationContext().authContext.authToken = token;
runtime:getInvocationContext().authenticationContext.scheme = "jwt";
runtime:getInvocationContext().authenticationContext.authToken = token;
}

function clearTokenFromAuthContext () {
runtime:getInvocationContext().authContext.scheme = "jwt";
runtime:getInvocationContext().authContext.authToken = "";
runtime:getInvocationContext().authenticationContext.scheme = "jwt";
runtime:getInvocationContext().authenticationContext.authToken = "";
}

function setInvalidJwtTokenToAuthContext () {
Expand All @@ -91,8 +91,8 @@ function setInvalidJwtTokenToAuthContext () {
"aPWGUnUoIExjYxrBMLGUTzMaM1knyI8agG7z6nKm0ZBMdti1AphGkqH50rDm9Arjvy256aNO-" +
"cw6lWkDneZl5WdV63RGNNNSj8ElyRW6HMdLmHQ3HIkQ4f1K8tCshwgbyb19bw8nCeYihpPeOn" +
"gVobfGY2yXm7QGjmiVInALAqisylo348WB6qOKduDrbDZYcFDKQuYConx5wF-7Wl9hg2HA";
runtime:getInvocationContext().authContext.scheme = "jwt";
runtime:getInvocationContext().authContext.authToken = token;
runtime:getInvocationContext().authenticationContext.scheme = "jwt";
runtime:getInvocationContext().authenticationContext.authToken = token;
}

function setJwtTokenWithNoScopesToAuthContext () {
Expand All @@ -105,6 +105,6 @@ function setJwtTokenWithNoScopesToAuthContext () {
"NhJRyht0GSa59VhonCFIAL505_u5vfO4fhmCjslYCr6WcpYW1tLf-vDmRLIqshYX7RZkK" +
"Es2a1pfjg5XkJiJSxqQ_-lLzeQfb-eMmZzT5ob-cE9qpBhjrXoYpYLy371TtuOdREdhXh" +
"Ogu12RJMaCE1FlA1ZoyLrmzj2Mm3RHc_A88lKoGvaEBcGzJwllekuQeDUJ1P90SGA";
runtime:getInvocationContext().authContext.scheme = "jwt";
runtime:getInvocationContext().authContext.authToken = token;
runtime:getInvocationContext().authenticationContext.scheme = "jwt";
runtime:getInvocationContext().authenticationContext.authToken = token;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ service wssService on securedListener2 {
}

http:AuthProvider basicAuthProvider = {
scheme: "basic",
authStoreProvider: "config"
scheme: http:BASIC_AUTH,
authStoreProvider: http:CONFIG_AUTH_STORE
};

http:AuthProvider basicAuthProvider2 = {
scheme: "basic",
authStoreProvider: "config"
scheme: http:BASIC_AUTH,
authStoreProvider: http:CONFIG_AUTH_STORE
};

listener http:Listener securedListener = new(9090, config = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"position": {
"line": 13,
"line": 15,
"character": 16
},
"source": "function/source/actionInvocationSuggestion1.bal",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"position": {
"line": 13,
"line": 15,
"character": 20
},
"source": "function/source/actionInvocationSuggestion2.bal",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"position": {
"line": 16,
"line": 18,
"character": 27
},
"source": "function/source/errorLiftingSuggestions1.bal",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ http:ClientEndpointConfig conf = {
url: "https://postman-echo.com/basic-auth",
auth: {
scheme: http:BASIC_AUTH,
username: "postman",
password: "password"
config: {
username: "postman",
password: "password"
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ http:ClientEndpointConfig conf = {
url: "https://postman-echo.com/basic-auth",
auth: {
scheme: http:BASIC_AUTH,
username: "postman",
password: "password"
config: {
username: "postman",
password: "password"
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ http:ClientEndpointConfig conf = {
url: "https://postman-echo.com/basic-auth",
auth: {
scheme: http:BASIC_AUTH,
username: "postman",
password: "password"
config: {
username: "postman",
password: "password"
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,36 @@
"sortText":"171",
"insertText":"AuthConfig"
},
{
"label":"BasicAuthConfig",
"kind":"Class",
"detail":"BType",
"documentation":{
"left":"BasicAuthConfig record can be used to configure Basic Authentication used by the HTTP endpoint.\n"
},
"sortText":"171",
"insertText":"BasicAuthConfig"
},
{
"label":"OAuth2AuthConfig",
"kind":"Class",
"detail":"BType",
"documentation":{
"left":"OAuth2AuthConfig record can be used to configure OAuth2 based authentication used by the HTTP endpoint.\n"
},
"sortText":"171",
"insertText":"OAuth2AuthConfig"
},
{
"label":"JwtAuthConfig",
"kind":"Class",
"detail":"BType",
"documentation":{
"left":"JwtAuthConfig record can be used to configure JWT based authentication used by the HTTP endpoint.\n"
},
"sortText":"171",
"insertText":"JwtAuthConfig"
},
{
"label":"HttpTimeoutError",
"kind":"Class",
Expand Down Expand Up @@ -880,6 +910,36 @@
"sortText":"171",
"insertText":"WebSocketClient"
},
{
"label":"InboundAuthScheme",
"kind":"Enum",
"detail":"BType",
"documentation":{
"left":"Inbound authentication schemes."
},
"sortText":"171",
"insertText":"InboundAuthScheme"
},
{
"label":"OutboundAuthScheme",
"kind":"Enum",
"detail":"BType",
"documentation":{
"left":"Outbound authentication schemes."
},
"sortText":"171",
"insertText":"OutboundAuthScheme"
},
{
"label":"AuthStoreProvider",
"kind":"Enum",
"detail":"BType",
"documentation":{
"left":"Authentication storage providers for BasicAuth scheme."
},
"sortText":"171",
"insertText":"AuthStoreProvider"
},
{
"label":"CachingPolicy",
"kind":"Enum",
Expand Down Expand Up @@ -930,13 +990,6 @@
"sortText":"171",
"insertText":"RedirectCode"
},
{
"label":"AuthScheme",
"kind":"Enum",
"detail":"BType",
"sortText":"171",
"insertText":"AuthScheme"
},
{
"label":"CredentialBearer",
"kind":"Enum",
Expand Down
Loading

0 comments on commit ba6e2eb

Please sign in to comment.