remix-auth-oauth2
Advanced tools
Comparing version
@@ -28,2 +28,3 @@ import { AppLoadContext, SessionStorage } from "@remix-run/server-runtime"; | ||
responseType?: ResponseType; | ||
useBasicAuthenticationHeader?: boolean; | ||
} | ||
@@ -87,2 +88,3 @@ export interface OAuth2StrategyVerifyParams<Profile extends OAuth2Profile, ExtraParams extends Record<string, unknown> = Record<string, never>> { | ||
protected responseType: ResponseType; | ||
protected useBasicAuthenticationHeader: boolean; | ||
private sessionStateKey; | ||
@@ -89,0 +91,0 @@ constructor(options: OAuth2StrategyOptions, verify: StrategyVerifyCallback<User, OAuth2StrategyVerifyParams<Profile, ExtraParams>>); |
@@ -56,3 +56,3 @@ "use strict"; | ||
constructor(options, verify) { | ||
var _a; | ||
var _a, _b; | ||
super(verify); | ||
@@ -67,2 +67,4 @@ this.name = "oauth2"; | ||
this.responseType = (_a = options.responseType) !== null && _a !== void 0 ? _a : "code"; | ||
this.useBasicAuthenticationHeader = | ||
(_b = options.useBasicAuthenticationHeader) !== null && _b !== void 0 ? _b : false; | ||
} | ||
@@ -218,4 +220,16 @@ async authenticate(request, sessionStorage, options) { | ||
async fetchAccessToken(code, params) { | ||
params.set("client_id", this.clientID); | ||
params.set("client_secret", this.clientSecret); | ||
let headers = { | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
}; | ||
if (this.useBasicAuthenticationHeader) { | ||
const b64EncodedCredentials = Buffer.from(`${this.clientID}:${this.clientSecret}`).toString("base64"); | ||
headers = { | ||
...headers, | ||
Authorization: `Basic ${b64EncodedCredentials}`, | ||
}; | ||
} | ||
else { | ||
params.set("client_id", this.clientID); | ||
params.set("client_secret", this.clientSecret); | ||
} | ||
if (params.get("grant_type") === "refresh_token") { | ||
@@ -229,3 +243,3 @@ params.set("refresh_token", code); | ||
method: "POST", | ||
headers: { "Content-Type": "application/x-www-form-urlencoded" }, | ||
headers, | ||
body: params, | ||
@@ -232,0 +246,0 @@ }); |
{ | ||
"name": "remix-auth-oauth2", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"main": "./build/index.js", | ||
@@ -5,0 +5,0 @@ "types": "./build/index.d.ts", |
@@ -35,2 +35,3 @@ # OAuth2Strategy | ||
callbackURL: "https://example.app/auth/callback", | ||
useBasicAuthenticationHeader: false // defaults to false | ||
}, | ||
@@ -37,0 +38,0 @@ async ({ accessToken, refreshToken, extraParams, profile, context }) => { |
25892
2.72%383
4.36%221
0.45%