@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
issuer
string, mandatory - The issuer of openid connect provider. This field is used to determine the provider discovery endpoint.clientId
string, mandatory - The application client_id registered in openid connect provider.clientSecret
string, mandatory - The client's secretresource
string, optional - Supported only in Azure AD V1. For other providers use scopescope
string, optional - A space-separated list of scopes.onTokenExpired
function, 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! Eitherresource
orscope
property should be set. For Azure AD v1 compatibility the request to Token endpoint has both properties (resource
andscope
) set with the same value provided inresource
orscope
properties.
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago