- Due to some dependency updates like Eslint, Node.js 10, 13, and 15 are no longer supported (see also Eslint 8.0.0 migration guide)
- Minor change in logging, to ensure a higher compatibility to multiple usable loggers
- updated nock and eslint
- added
.npmrc
for reliable builds
- fix linting error
- remove the last left over dependencies and files for TSLint
- fix npm task
- Change type
Record<string, unknown>
toRecord<string | number | symbol, unknown>
to support the full range of possible keys within anobject
- security updates and dependency updates
This release is mostly about dependency updates and cleaning up, and probably non-breaking. However there are some types affected by changes due to an updated TypeScript version so we are not 100% sure about this. If you identify breaking behaviour/changes in this release, feel free to reach out to us.
Additional information 29.01.2021
We removed as highly encouraged within Typescript the type {}
by the type Record<string | number | symbol, unknown>
in an exported interface. Meanwhile, we assume the interface is not breaking and experienced no problems since release.
Nevertheless we dropped the support for some older and unsupported Node versions with the first official release of this mayor version.
The following functions got support for an optional logger:
TokenCache
(viaTokenCacheOptions
parameter)getTokenInfo
(vialogger
parameter)getAccessToken
(vialogger
parameter)authenticationMiddleware
(viaAuthenticationMiddlewareOptions
parameter)requireScopesMiddleware
(viaScopeMiddlewareOptions
parameter)
Providing a logger is optional. Any logger needs to satisfy the Logger interface.
To keep arguments lists short, option
objects were introduced to group a number of (mostly) optional parameters.
-
handleOAuthRequestMiddleware
was renamed toauthenticationMiddleware
- Config parameter
MiddlewareOptions
was renamed toAuthenticationMiddlewareOptions
- An optional logger can be provided (
Logger
) - An optional
onNotAuthenticatedHandler
can be provided, which let you explicitly handle the case when authentication fails. Important note: ifonNotAuthenticatedHandler
is defined you are responsible to handle the request yourself (e.g. callingresponse.sendStatus(code)
ornext()
).
- Config parameter
-
requireScopesMiddleware
- Added optional
options
object of typeScopeMiddlewareOptions
- An optional logger can be provided (
Logger
) - An optional
onAuthorizationFailedHandler
can be provided, which let you explicitly handle the case when authentication fails. Important note: ifonAuthorizationFailedHandler
is defined you are responsible to handle the request yourself (e.g. callingresponse.sendStatus(code)
ornext()
).
- An optional logger can be provided (
- Moved
precedenceOptions
parameter intooptions
parameterprecedenceErrorHandler
got removed fromPrecedenceOptions
.onAuthorizationFailedHandler
should be used instead.
- Added optional
The TokenCacheConfig
parameter type is now called TokenCacheOptions
and looks like:
type CacheConfig = {
percentageLeft: number
};
type TokenCacheOptions = {
cacheConfig?: CacheConfig,
logger?: Logger
};
Instead of providing one bulky type for all OAuth2 grants the type OAuthConfig
is split up into a union type of all supported grants. A type for the TokenCache
config (TokenCacheOAuthConfig
) is also derived:
type OAuthConfig =
ClientCredentialsGrantConfig |
AuthorizationCodeGrantConfig |
PasswordCredentialsGrantConfig |
RefreshGrantConfig;
type TokenCacheOAuthConfig = OAuthConfig & {
tokenInfoEndpoint: string;
};
It is now possible to provide an optional object bodyParams
which will be appended to the request body when requesting a token (via getAccessToken
or TokenCache
):
const config: OAuthConfig = {
...,
bodyParams: {
business_partner_id: 'xxx-xxx-xxx'
}
};
It is now possible to provide client (and user) credentials as a string
instead of just via a credentialsDir
:
const config: OAuthConfig = {
...,
clientId,
clientSecret,
applicationUsername,
applicationPassword
};
For detailed information have a look at the implementation of OAuthConfig
.
Instead of four single string values, an enum OAuthGrantType
is exported which should be used as grantType
in OAuthConfig
:
enum OAuthGrantType {
AUTHORIZATION_CODE_GRANT = 'authorization_code',
PASSWORD_CREDENTIALS_GRANT = 'password',
REFRESH_TOKEN_GRANT = 'refresh_token',
CLIENT_CREDENTIALS_GRANT = 'client_credentials'
}
The type for the optional parameter queryParams
is changed from {}
to the more specific { [index: string]: string }
.
Before this release, mockAccessTokenEndpoint
always includes uid
as value of the scopes
property in the returned token. Now, mockAccessTokenEndpoint
includes the scopes which were requested by the HTTP request. A request like:
getAccessToken({
...,
scopes: ['uid', 'test']
})
...will lead to a response with a token which includes the scopes uid
and test
. If no scopes
are requested, the scopes
property of the token will be undefined
.
Token was moved out of MockOptions
into a separate parameter: mockTokeninfoEndpoint(options: MockOptions, tokens?: Token[]): nock.Scope
.
The library now exports mockTokeninfoEndpointWithErrorResponse
and mockAccessTokenEndpointWithErrorResponse
which allow to mock an OAuth endpoint with an error response to be able to test behaviour in error case more accurate:
mockTokeninfoEndpointWithErrorResponse(options: MockOptions, httpStatus: number, responseBody?: object): void
mockAccessTokenEndpointWithErrorResponse(options: MockOptions, httpStatus: number, responseBody?: object): void
Both functions set up a HTTP mock via nock. A request to the mocked url (defined via MockOptions
) will lead to a response with the given httpStatus
and, if defined, responseBody
(otherwise {}
).
Promises returned by getAccessToken
and getTokenInfo
are now rejected in a consistent way with an error object like:
{
error?: string | Error | object,
message?: string
}
The project was renamed from lib-oauth-tooling
to authmosphere
. In the course of this renaming versioning was restarted at 1.0.0
.
Modified signature of createAuthCodeRequestUri
, see migration guide for more information.
The (zalando-specific) realm
property was removed from OAuthConfig
. Also, the corresponding constants (SERVICES_REALM
and EMPLYEES_REALM
) were removed. Instead, you can add the realm (and arbitrary other query parameters) via the queryParams
property in OAuthConfig
.
The signature of requireScopesMiddleware
is now incompatible with previous versions, precedenceFunction?
is now part of precedenceOptions?
.