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

Implement declarative auth design for GraphQL service #210

Merged
merged 7 commits into from
May 12, 2021

Conversation

ldclakmal
Copy link
Member

@ldclakmal ldclakmal commented May 11, 2021

Purpose

This PR introduces the declarative auth design for GraphQL service.

Design: https://docs.google.com/document/d/1dGw5uUP6kqZNTwMfQ_Ik-k0HTMKhX70XpEA3tys9_kk/edit?usp=sharing

Fixes: ballerina-platform/ballerina-library#1336
Related to ballerina-platform/ballerina-library#584

Examples

@graphql:ServiceConfiguration {
    auth: [
        {
            oauth2IntrospectionConfig: {
                url: "https://localhost:9445/oauth2/introspect",
                tokenTypeHint: "access_token",
                scopeKey: "scp",
                clientConfig: {
                    secureSocket: {
                       cert: {
                           path: TRUSTSTORE_PATH,
                           password: "ballerina"
                       }
                    }
                }
            },
            scopes: ["write", "update"]
        },
        {
            fileUserStoreConfig: {},
            scopes: ["write", "update"]
        },
        {
            jwtValidatorConfig: {
                issuer: "wso2",
                audience: "ballerina",
                signatureConfig: {
                    trustStoreConfig: {
                        trustStore: {
                            path: TRUSTSTORE_PATH,
                            password: "ballerina"
                        },
                        certAlias: "ballerina"
                    }
                },
                scopeKey: "scp"
            },
            scopes: ["write", "update"]
        }
    ]
}
service /graphql on new graphql:Listener(9090) {
    isolated resource function get greeting() returns string {
        return "Hello World!";
    }
}

Checklist

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

@codecov
Copy link

codecov bot commented May 11, 2021

Codecov Report

Merging #210 (8aff759) into master (cc8828c) will decrease coverage by 0.03%.
The diff coverage is 87.50%.

❗ Current head 8aff759 differs from pull request most recent head 37bbda7. Consider uploading reports for the commit 37bbda7 to get more accurate results
Impacted file tree graph

@@             Coverage Diff              @@
##             master     #210      +/-   ##
============================================
- Coverage     90.12%   90.08%   -0.04%     
  Complexity      204      204              
============================================
  Files            41       43       +2     
  Lines          1691     1796     +105     
  Branches        695      753      +58     
============================================
+ Hits           1524     1618      +94     
- Misses          153      164      +11     
  Partials         14       14              
Impacted Files Coverage Δ Complexity Δ
graphql-ballerina/annotations.bal 100.00% <ø> (ø) 0.00 <0.00> (ø)
graphql-ballerina/auth_types.bal 80.00% <80.00%> (ø) 0.00 <0.00> (?)
graphql-ballerina/auth_processor.bal 85.93% <85.93%> (ø) 0.00 <0.00> (?)
graphql-ballerina/annotation_processor.bal 100.00% <100.00%> (ø) 0.00 <0.00> (ø)
graphql-ballerina/engine.bal 82.69% <100.00%> (+0.69%) 0.00 <0.00> (ø)
graphql-ballerina/http_service.bal 100.00% <100.00%> (ø) 0.00 <0.00> (ø)
graphql-ballerina/modules/parser/types.bal 50.00% <0.00%> (ø) 0.00% <0.00%> (ø%)
graphql-ballerina/modules/parser/parser.bal 92.30% <0.00%> (+0.04%) 0.00% <0.00%> (ø%)
... and 1 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 cc8828c...37bbda7. Read the comment docs.

@ldclakmal ldclakmal marked this pull request as ready for review May 11, 2021 12:49
@shafreenAnfar
Copy link
Contributor

LGTM

Copy link
Member

@ThisaruGuruge ThisaruGuruge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a couple of minor comments, but overall, LGTM.

Comment on lines 36 to 37
ListenerAuthConfig[] auth = <ListenerAuthConfig[]>serviceConfig?.auth;
return auth;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we directly return here?

Suggested change
ListenerAuthConfig[] auth = <ListenerAuthConfig[]>serviceConfig?.auth;
return auth;
return <ListenerAuthConfig[]>serviceConfig?.auth;

}
}

isolated function tryAuthenticate(ListenerAuthConfig[] authConfig, string header) returns http:Unauthorized|http:Forbidden? {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we use plural names for arrays? Like authConfigs?

}
}

@test:Config {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we add a test group for auth tests?

Suggested change
@test:Config {}
@test:Config {
groups: ["auth"]
}

@ThisaruGuruge ThisaruGuruge merged commit 7ecafb3 into master May 12, 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.

Implement declarative auth design for GraphQL module
3 participants