@clearfor/remix-auth-auth0
Advanced tools
Comparing version 1.0.0-beta.2 to 1.0.0-beta.3
import { type SetCookieInit } from "@mjackson/headers"; | ||
import { Auth0, type OAuth2Tokens } from "arctic"; | ||
import { type OAuth2Tokens } from "arctic"; | ||
import { Strategy } from "remix-auth/strategy"; | ||
@@ -46,2 +46,35 @@ type URLConstructor = ConstructorParameters<typeof URL>[0]; | ||
}; | ||
export interface Auth0Profile { | ||
id: string; | ||
displayName?: string; | ||
name?: { | ||
familyName?: string; | ||
givenName?: string; | ||
middleName?: string; | ||
}; | ||
emails?: { | ||
value: string; | ||
}[]; | ||
photos?: { | ||
value: string; | ||
}[]; | ||
organizationId?: string; | ||
organizationName?: string; | ||
_json: Auth0UserInfo; | ||
} | ||
export interface Auth0UserInfo { | ||
sub: string; | ||
name?: string; | ||
family_name?: string; | ||
given_name?: string; | ||
middle_name?: string; | ||
nickname?: string; | ||
profile?: string; | ||
picture?: string; | ||
website?: string; | ||
email?: string; | ||
email_verified: boolean; | ||
org_id?: string; | ||
org_name?: string; | ||
} | ||
interface VerifyOptions { | ||
@@ -56,3 +89,4 @@ /** The request that triggered the verification flow */ | ||
name: string; | ||
protected client: Auth0; | ||
private client; | ||
private userInfoURL; | ||
constructor(options: Auth0Options, verify: Strategy.VerifyFunction<User, VerifyOptions>); | ||
@@ -103,3 +137,4 @@ private get cookieName(); | ||
revokeToken(token: string): Promise<void>; | ||
userProfile(accessToken: string): Promise<Auth0Profile>; | ||
} | ||
export {}; |
@@ -13,5 +13,7 @@ import {} from "@mjackson/headers"; | ||
client; | ||
userInfoURL; | ||
constructor(options, verify) { | ||
super(verify); | ||
this.options = options; | ||
this.userInfoURL = `https://${options.domain}/userinfo`; | ||
this.client = new Auth0(options.domain, options.clientId, options.clientSecret, options.redirectURI.toString()); | ||
@@ -128,3 +130,41 @@ } | ||
} | ||
async userProfile(accessToken) { | ||
let response = await fetch(this.userInfoURL, { | ||
headers: { Authorization: `Bearer ${accessToken}` }, | ||
}); | ||
let data = await response.json(); | ||
let profile = { | ||
id: data.sub, | ||
_json: data, | ||
}; | ||
if (data.name) { | ||
profile.displayName = data.name; | ||
} | ||
if (data.family_name || data.given_name || data.middle_name) { | ||
profile.name = {}; | ||
if (data.family_name) { | ||
profile.name.familyName = data.family_name; | ||
} | ||
if (data.given_name) { | ||
profile.name.givenName = data.given_name; | ||
} | ||
if (data.middle_name) { | ||
profile.name.middleName = data.middle_name; | ||
} | ||
} | ||
if (data.email) { | ||
profile.emails = [{ value: data.email }]; | ||
} | ||
if (data.picture) { | ||
profile.photos = [{ value: data.picture }]; | ||
} | ||
if (data.org_id) { | ||
profile.organizationId = data.org_id; | ||
} | ||
if (data.org_name) { | ||
profile.organizationName = data.org_name; | ||
} | ||
return profile; | ||
} | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@clearfor/remix-auth-auth0", | ||
"version": "1.0.0-beta.2", | ||
"version": "1.0.0-beta.3", | ||
"description": "Remix auth wrapper for Auth0", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
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
Network access
Supply chain riskThis module accesses the network.
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
31345
468
1