import ballerina/graphql;
listener graphql:Listener securedEP = new(9090,
secureSocket = {
key: {
certFile: "../resource/path/to/public.crt",
keyFile: "../resource/path/to/private.key"
}
}
);
// The service can be secured with JWT Auth and can be authorized
// optionally. JWT Auth can be enabled by setting the
// `graphql:JwtValidatorConfig` configurations.
// Authorization is based on scopes. A scope maps to one or more groups.
// Authorization can be enabled by setting the `string|string[]` type
// configurations for `scopes` field.
@graphql:ServiceConfig {
auth: [
{
jwtValidatorConfig: {
issuer: "wso2",
audience: "ballerina",
signatureConfig: {
certFile: "../resource/path/to/public.crt"
},
scopeKey: "scp"
},
scopes: ["admin"]
}
]
}
service /graphql on securedEP {
resource function get greeting() returns string {
return "Hello, World!";
}
}
Service - JWT AuthA GraphQL service can be secured with JWT and by enforcing
authorization optionally. Then, it validates the JWT sent in the
|
import ballerina/graphql;
listener graphql:Listener securedEP = new(9090,
secureSocket = {
key: {
certFile: "../resource/path/to/public.crt",
keyFile: "../resource/path/to/private.key"
}
}
);
@graphql:ServiceConfig {
auth: [
{
jwtValidatorConfig: {
issuer: "wso2",
audience: "ballerina",
signatureConfig: {
certFile: "../resource/path/to/public.crt"
},
scopeKey: "scp"
},
scopes: ["admin"]
}
]
}
service /graphql on securedEP {
resource function get greeting() returns string {
return "Hello, World!";
}
}
The service can be secured with JWT Auth and can be authorized
optionally. JWT Auth can be enabled by setting the
graphql:JwtValidatorConfig
configurations.
Authorization is based on scopes. A scope maps to one or more groups.
Authorization can be enabled by setting the string|string[]
type
configurations for scopes
field.
# You may need to change the certificate file path and private key file path.
bal run graphql_service_jwt_auth.bal