Search code examples
httpserviceballerina

Define scopes at resource level of service in Ballerina


In the following BBE, scopes are defined at the service level.

Is there a way to define the expected scopes at the resource level?

https://ballerina.io/learn/by-example/http-service-oauth2/


Solution

  • We can do it by using @http:ResourceConfig annotation.

    https://lib.ballerina.io/ballerina/http/latest#HttpResourceConfig

    ex:

    
        @http:ResourceConfig {
            auth: {
                scopes: ["admin"]
            }
        }
        resource function get albums() returns Album[] {
            return [
                {title: "Blue Train", artist: "John Coltrane"},
                {title: "Jeru", artist: "Gerry Mulligan"}
            ];
        }
    }