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

Commit

Permalink
Merge pull request #158 from flexpa/feature/tokenParams
Browse files Browse the repository at this point in the history
Added tokenParams to SmartAuthProvider
  • Loading branch information
kodiakhq[bot] authored Dec 8, 2021
2 parents 5672586 + 05a27af commit 1947eb2
Showing 1 changed file with 11 additions and 5 deletions.
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

0 comments on commit 1947eb2

Please sign in to comment.