@npmsoluto/authorized-fetch v1.2.0
authorized-fetch
This module wraps fetch and allows to acquire authorization token before making request.
It caches tokens and avoids redundant calls to oauth provider. Expired tokens are invalidated and replaced by new ones.
API
getAuthenticationToken
async (authenticationParams: AuthenticationParams) => Promise<string>
Function that receives AuthenticationParams and returns promise of the access token.
default
async (authenticationParams: AuthenticationParams, fetch?: FetchAPI, init: RequestInit = {}) => Promise<Response>
Function that creates fetch object that wraps user-provided fetch with getAuthenticationToken function that is called before each request and the access token is set to the Authorization header.
AuthenticationParams
issuerstring, mandatory - The issuer of openid connect provider. This field is used to determine the provider discovery endpoint.clientIdstring, mandatory - The application client_id registered in openid connect provider.clientSecretstring, mandatory - The client's secretresourcestring, optional - Supported only in Azure AD V1. For other providers use scopescopestring, optional - A space-separated list of scopes.onTokenExpiredfunction, optional - Hook that' fired on token renewal.
Note: The module makes request to the Token Endpoint of oidc provider with
grant_type=client_credentials. Important! Eitherresourceorscopeproperty should be set. For Azure AD v1 compatibility the request to Token endpoint has both properties (resourceandscope) set with the same value provided inresourceorscopeproperties.
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago