Skip to content

Instantly share code, notes, and snippets.

@nflaig
Last active December 31, 2020 21:56
Show Gist options
  • Save nflaig/7aa83b7c176fb718c54dd99e97fff3a3 to your computer and use it in GitHub Desktop.
Save nflaig/7aa83b7c176fb718c54dd99e97fff3a3 to your computer and use it in GitHub Desktop.
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