Skip to content
This repository has been archived by the owner on Jun 13, 2022. It is now read-only.

Added tokenParams to SmartAuthProvider #158

Merged
merged 2 commits into from
Dec 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/smart-auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,19 @@ export type SmartAuthProvider = {
pathPrefix?: string;
/** Optional params to append to the authorization redirect */
authorizeParams?: Record<string, any>;
/** String used to set the host to request an "authorization code". Default to the value set on auth.tokenHost. */
authorizeHost?: string;
/** String path to request an authorization code. Default to /oauth/authorize. */
authorizePath?: string;
/** Optional params to post to the token exchange */
tokenParams?: Record<string, any>;
/** String used to set the host to request the tokens to. Required. */
tokenHost: string;
/** String path to request an access token. Default to /oauth/token. */
tokenPath?: string;
/** String path to revoke an access token. Default to /oauth/revoke. */
revokePath?: string;
/** String used to set the host to request an "authorization code". Default to the value set on auth.tokenHost. */
authorizeHost?: string;
/** String path to request an authorization code. Default to /oauth/authorize. */
authorizePath?: string;

};
redirect: {
/** A required host name for the auth code exchange redirect path. */
Expand Down Expand Up @@ -115,6 +118,7 @@ const oauthPlugin: FastifyPluginCallback<SmartAuthProvider> = function (http, op
const { name, auth, client, scope: defaultScope, redirect } = options

const prefix = auth?.pathPrefix || "/smart";
const tokenParams = auth?.tokenParams || {}
const tokenHost = auth.tokenHost;
const authorizeParams = auth?.authorizeParams || {}
const authorizeRedirectPath = `${prefix}/${routeCase(name)}/auth`
Expand Down Expand Up @@ -150,10 +154,12 @@ const oauthPlugin: FastifyPluginCallback<SmartAuthProvider> = function (http, op

checkState(state);

return await this.authorizationCodeFlow.getToken({
const params = Object.assign({}, tokenParams, {
code: code,
redirect_uri: redirectUri
})

return await this.authorizationCodeFlow.getToken(params)
}

async function getNewAccessTokenUsingRefreshToken(
Expand Down