Last active
December 31, 2020 21:56
-
-
Save nflaig/7aa83b7c176fb718c54dd99e97fff3a3 to your computer and use it in GitHub Desktop.
This file contains 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
import { bind } from "@loopback/core"; | |
import { | |
asSpecEnhancer, | |
mergeOpenAPISpec, | |
OASEnhancer, | |
OpenApiSpec, | |
OpenAPIObject | |
} from "@loopback/rest"; | |
const authServerUrl = process.env.AUTH_SERVER_URL; | |
const tokenUrl = `${authServerUrl}/oauth/token`; | |
const authorizationUrl = `${authServerUrl}/oauth/authorize`; | |
const OAuth2Spec: Partial<OpenAPIObject> = { | |
components: { | |
securitySchemes: { | |
OAuth2: { | |
type: "oauth2", | |
description: "OAuth 2.0 flows", | |
flows: { | |
authorizationCode: { | |
authorizationUrl, | |
tokenUrl, | |
scopes: {} | |
}, | |
implicit: { | |
authorizationUrl, | |
scopes: {} | |
}, | |
clientCredentials: { | |
tokenUrl, | |
scopes: {} | |
}, | |
password: { | |
tokenUrl, | |
scopes: {} | |
} | |
} | |
} | |
} | |
}, | |
security: [ | |
{ | |
OAuth2: [] | |
} | |
] | |
}; | |
@bind(asSpecEnhancer) | |
export class OAuth2SpecEnhancer implements OASEnhancer { | |
name = "OAuth2"; | |
modifySpec(spec: OpenApiSpec): OpenApiSpec { | |
return mergeOpenAPISpec(spec, OAuth2Spec); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment