parent
a82d3f310e
commit
e3c6b60211
|
@ -2,7 +2,6 @@ import { generateGlobalUserID } from "../../../db"
|
||||||
import { authError } from "../utils"
|
import { authError } from "../utils"
|
||||||
import * as users from "../../../users"
|
import * as users from "../../../users"
|
||||||
import * as context from "../../../context"
|
import * as context from "../../../context"
|
||||||
import fetch from "node-fetch"
|
|
||||||
import {
|
import {
|
||||||
SaveSSOUserFunction,
|
SaveSSOUserFunction,
|
||||||
SSOAuthDetails,
|
SSOAuthDetails,
|
||||||
|
@ -97,28 +96,13 @@ export async function authenticate(
|
||||||
return done(null, ssoUser)
|
return done(null, ssoUser)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getProfilePictureUrl(user: User, details: SSOAuthDetails) {
|
|
||||||
const pictureUrl = details.profile?._json.picture
|
|
||||||
if (pictureUrl) {
|
|
||||||
const response = await fetch(pictureUrl)
|
|
||||||
if (response.status === 200) {
|
|
||||||
const type = response.headers.get("content-type") as string
|
|
||||||
if (type.startsWith("image/")) {
|
|
||||||
return pictureUrl
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns a user that has been sync'd with third party information
|
* @returns a user that has been sync'd with third party information
|
||||||
*/
|
*/
|
||||||
async function syncUser(user: User, details: SSOAuthDetails): Promise<SSOUser> {
|
async function syncUser(user: User, details: SSOAuthDetails): Promise<SSOUser> {
|
||||||
let firstName
|
let firstName
|
||||||
let lastName
|
let lastName
|
||||||
let pictureUrl
|
|
||||||
let oauth2
|
let oauth2
|
||||||
let thirdPartyProfile
|
|
||||||
|
|
||||||
if (details.profile) {
|
if (details.profile) {
|
||||||
const profile = details.profile
|
const profile = details.profile
|
||||||
|
@ -134,12 +118,6 @@ async function syncUser(user: User, details: SSOAuthDetails): Promise<SSOUser> {
|
||||||
lastName = name.familyName
|
lastName = name.familyName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pictureUrl = await getProfilePictureUrl(user, details)
|
|
||||||
|
|
||||||
thirdPartyProfile = {
|
|
||||||
...profile._json,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// oauth tokens for future use
|
// oauth tokens for future use
|
||||||
|
@ -155,8 +133,6 @@ async function syncUser(user: User, details: SSOAuthDetails): Promise<SSOUser> {
|
||||||
providerType: details.providerType,
|
providerType: details.providerType,
|
||||||
firstName,
|
firstName,
|
||||||
lastName,
|
lastName,
|
||||||
thirdPartyProfile,
|
|
||||||
pictureUrl,
|
|
||||||
oauth2,
|
oauth2,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,10 +59,8 @@ export function ssoAccount(account: Account = cloudAccount()): SSOAccount {
|
||||||
accessToken: generator.string(),
|
accessToken: generator.string(),
|
||||||
refreshToken: generator.string(),
|
refreshToken: generator.string(),
|
||||||
},
|
},
|
||||||
pictureUrl: generator.url(),
|
|
||||||
provider: provider(),
|
provider: provider(),
|
||||||
providerType: providerType(),
|
providerType: providerType(),
|
||||||
thirdPartyProfile: {},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,9 +74,7 @@ export function verifiableSsoAccount(
|
||||||
accessToken: generator.string(),
|
accessToken: generator.string(),
|
||||||
refreshToken: generator.string(),
|
refreshToken: generator.string(),
|
||||||
},
|
},
|
||||||
pictureUrl: generator.url(),
|
|
||||||
provider: AccountSSOProvider.MICROSOFT,
|
provider: AccountSSOProvider.MICROSOFT,
|
||||||
providerType: AccountSSOProviderType.MICROSOFT,
|
providerType: AccountSSOProviderType.MICROSOFT,
|
||||||
thirdPartyProfile: { id: "abc123" },
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ export const user = (userProps?: Partial<Omit<User, "userId">>): User => {
|
||||||
roles: { app_test: "admin" },
|
roles: { app_test: "admin" },
|
||||||
firstName: generator.first(),
|
firstName: generator.first(),
|
||||||
lastName: generator.last(),
|
lastName: generator.last(),
|
||||||
pictureUrl: "http://example.com",
|
|
||||||
tenantId: tenant.id(),
|
tenantId: tenant.id(),
|
||||||
...userProps,
|
...userProps,
|
||||||
}
|
}
|
||||||
|
@ -86,9 +85,5 @@ export function ssoUser(
|
||||||
oauth2: opts.details?.oauth2,
|
oauth2: opts.details?.oauth2,
|
||||||
provider: opts.details?.provider!,
|
provider: opts.details?.provider!,
|
||||||
providerType: opts.details?.providerType!,
|
providerType: opts.details?.providerType!,
|
||||||
thirdPartyProfile: {
|
|
||||||
email: base.email,
|
|
||||||
picture: base.pictureUrl,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ export interface CreateAccountRequest {
|
||||||
name?: string
|
name?: string
|
||||||
password: string
|
password: string
|
||||||
provider?: AccountSSOProvider
|
provider?: AccountSSOProvider
|
||||||
thirdPartyProfile: object
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SearchAccountsRequest {
|
export interface SearchAccountsRequest {
|
||||||
|
|
|
@ -98,8 +98,6 @@ export interface AccountSSO {
|
||||||
provider: AccountSSOProvider
|
provider: AccountSSOProvider
|
||||||
providerType: AccountSSOProviderType
|
providerType: AccountSSOProviderType
|
||||||
oauth2?: OAuthTokens
|
oauth2?: OAuthTokens
|
||||||
pictureUrl?: string
|
|
||||||
thirdPartyProfile: any // TODO: define what the google profile looks like
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SSOAccount = (Account | CloudAccount) & AccountSSO
|
export type SSOAccount = (Account | CloudAccount) & AccountSSO
|
||||||
|
|
|
@ -21,7 +21,6 @@ export interface UserSSO {
|
||||||
provider: string // the individual provider e.g. Okta, Auth0, Google
|
provider: string // the individual provider e.g. Okta, Auth0, Google
|
||||||
providerType: SSOProviderType
|
providerType: SSOProviderType
|
||||||
oauth2?: OAuth2
|
oauth2?: OAuth2
|
||||||
thirdPartyProfile?: SSOProfileJson
|
|
||||||
profile?: {
|
profile?: {
|
||||||
displayName?: string
|
displayName?: string
|
||||||
name?: {
|
name?: {
|
||||||
|
@ -45,7 +44,6 @@ export interface User extends Document {
|
||||||
userId?: string
|
userId?: string
|
||||||
firstName?: string
|
firstName?: string
|
||||||
lastName?: string
|
lastName?: string
|
||||||
pictureUrl?: string
|
|
||||||
forceResetPassword?: boolean
|
forceResetPassword?: boolean
|
||||||
roles: UserRoles
|
roles: UserRoles
|
||||||
builder?: {
|
builder?: {
|
||||||
|
|
Loading…
Reference in New Issue