remix-auth-oauth2
Advanced tools
Comparing version 1.4.0 to 1.5.0
@@ -93,8 +93,9 @@ "use strict"; | ||
debug("State from URL", stateUrl); | ||
if (!stateUrl) | ||
throw (0, server_runtime_1.json)({ message: "Missing state on URL." }, { status: 400 }); | ||
if (!stateUrl) { | ||
return await this.failure("Missing state on URL.", request, sessionStorage, options, new Error("Missing state on URL.")); | ||
} | ||
let stateSession = session.get(this.sessionStateKey); | ||
debug("State from session", stateSession); | ||
if (!stateSession) { | ||
throw (0, server_runtime_1.json)({ message: "Missing state on session." }, { status: 400 }); | ||
return await this.failure("Missing state on session.", request, sessionStorage, options, new Error("Missing state on session.")); | ||
} | ||
@@ -105,16 +106,18 @@ if (stateSession === stateUrl) { | ||
} | ||
else | ||
throw (0, server_runtime_1.json)({ message: "State doesn't match." }, { status: 400 }); | ||
else { | ||
return await this.failure("State doesn't match.", request, sessionStorage, options, new Error("State doesn't match.")); | ||
} | ||
let code = url.searchParams.get("code"); | ||
if (!code) | ||
throw (0, server_runtime_1.json)({ message: "Missing code." }, { status: 400 }); | ||
// Get the access token | ||
let params = new URLSearchParams(this.tokenParams()); | ||
params.set("grant_type", "authorization_code"); | ||
params.set("redirect_uri", callbackURL.toString()); | ||
let { accessToken, refreshToken, extraParams } = await this.fetchAccessToken(code, params); | ||
// Get the profile | ||
let profile = await this.userProfile(accessToken, extraParams); | ||
// Verify the user and return it, or redirect | ||
if (!code) { | ||
return await this.failure("Missing code.", request, sessionStorage, options, new Error("Missing code.")); | ||
} | ||
try { | ||
// Get the access token | ||
let params = new URLSearchParams(this.tokenParams()); | ||
params.set("grant_type", "authorization_code"); | ||
params.set("redirect_uri", callbackURL.toString()); | ||
let { accessToken, refreshToken, extraParams } = await this.fetchAccessToken(code, params); | ||
// Get the profile | ||
let profile = await this.userProfile(accessToken, extraParams); | ||
// Verify the user and return it, or redirect | ||
user = await this.verify({ | ||
@@ -229,9 +232,4 @@ accessToken, | ||
if (!response.ok) { | ||
try { | ||
let body = await response.text(); | ||
throw new Response(body, { status: 401 }); | ||
} | ||
catch (error) { | ||
throw new Response(error.message, { status: 401 }); | ||
} | ||
let body = await response.text(); | ||
throw body; | ||
} | ||
@@ -238,0 +236,0 @@ return await this.getAccessToken(response.clone()); |
{ | ||
"name": "remix-auth-oauth2", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"main": "./build/index.js", | ||
@@ -5,0 +5,0 @@ "types": "./build/index.d.ts", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25206
367