Executes OAuth2 authorization flow for a given provider based on configuration
- Install all the dependencies:
npm i - Modify
configurationvariable inindex.jsfile to suit your desired OAuth2 provider - Modify
serverless.ymlinserting the app id where required - Add
.envfile with needed env variables
CLIENT_ID - provider client id
CLIENT_SECRET - provider client secret
Example:
CLIENT_ID=31523524302fjfj02jff0249
CLIENT_SECRET=4095hjfhfjhfeihf3jho3j4hgo34j
The authorizeUrl section pertains to the provider url responsible for authorizing the user. The scope
field is the only required field, but additional fields can be added as needed by the provider. Any
additional fields will be included as query params (key=value) for the authorize request.
The innerAuthorization parameter is optional parameter, which is used to make sure that inner
service used within outer service is accessible with stored accessToken. If this field is not
empty then for each /refresh request the innerAuthorization.url is called (with options:
innerAuthorization.headers and innerAuthorization.method if given or method GET otherwise).
Field accessToken stored in
OAuth Table is used as authorization token, if given. If url response give back Unauthorized or
Forbidden status, then
- appropriate
OAuth TablegoterrorCode = INNER_AUTHORIZATION_FAILED.code - if additionally
innerAuhtorization.removeCredentialsis given and set totruethen appropriateOAuth Tableis cleaned up in the same way as the user logging out.
The credentialKeys parameter is optional parameter, which is used to store custom credentials keys,
which are set into oauth2 client.id and client.secret. If missing default values (CLIENT_ID, CLIENT_SECRET)
are applied. If keys are defined for specific settings, the Environment variables with given keys, should be provided.