Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions src/main/__tests__/sessionDevices.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import fetchMock from 'jest-fetch-mock'
import { defineWindowProperty, headers, mockWindowCrypto } from './helpers/testHelpers'
import { popNextRandomString } from './helpers/randomStringMock'
import { createDefaultTestClient } from './helpers/clientFactory'

beforeAll(() => {
fetchMock.enableMocks()
defineWindowProperty('location')
defineWindowProperty('crypto', mockWindowCrypto)
})

beforeEach(() => {
document.body.innerHTML = ''
jest.resetAllMocks()
fetchMock.resetMocks()
popNextRandomString()
})

test('list session devices', async () => {
// Given
const { client, domain } = createDefaultTestClient()
const accessToken = '456'

const listSessionDevicesCall = fetchMock.mockResponseOnce(
JSON.stringify({
sessionDevices: [
{
id: "UUID",
ip: "192.168.65.1",
operatingSystem: "Android",
userAgentName: "Chrome",
deviceClass: "Phone",
deviceName: "Google Nexus 6",
firstConnection: "date1",
lastConnection: "date2"
}
]
})
)

const result = await client.listSessionDevices(accessToken)

expect(listSessionDevicesCall).toHaveBeenCalledWith(
`https://${domain}/identity/v1/session-devices`,
{
method: 'GET',
headers: expect.objectContaining({
...headers.accessToken(accessToken)
})
}
)

expect(result).toEqual({
sessionDevices: [
{
id: "UUID",
ip: "192.168.65.1",
operatingSystem: "Android",
userAgentName: "Chrome",
deviceClass: "Phone",
deviceName: "Google Nexus 6",
firstConnection: "date1",
lastConnection: "date2"
}
]
})

})
9 changes: 8 additions & 1 deletion src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
PasswordlessResponse,
MFA,
OrchestrationToken,
PasswordStrength
PasswordStrength,
SessionDeviceListResponse
} from './models'
import OAuthClient, {
LoginWithPasswordParams,
Expand Down Expand Up @@ -96,6 +97,7 @@ export type Client = {
getSignupData: (signupToken: string) => Promise<OpenIdUser>
getUser: (params: GetUserParams) => Promise<Profile>
listMfaCredentials: (accessToken: string) => Promise<CredentialsResponse>
listSessionDevices: (accessToken: string) => Promise<SessionDeviceListResponse>
listTrustedDevices: (accessToken: string) => Promise<ListTrustedDevicesResponse>
listWebAuthnDevices: (accessToken: string) => Promise<DeviceCredential[]>
loginFromSession: (options?: AuthOptions) => Promise<void>
Expand Down Expand Up @@ -264,6 +266,10 @@ export function createClient(creationConfig: Config): Client {
return apiClients.then((clients) => clients.mfa.listMfaCredentials(accessToken))
}

function listSessionDevices(accessToken: string) {
return apiClients.then((clients) => clients.profile.listSessionDevices(accessToken))
}

function listWebAuthnDevices(accessToken: string) {
return apiClients.then((clients) => clients.webAuthn.listWebAuthnDevices(accessToken))
}
Expand Down Expand Up @@ -450,6 +456,7 @@ export function createClient(creationConfig: Config): Client {
getSignupData,
getUser,
listMfaCredentials,
listSessionDevices,
listTrustedDevices,
listWebAuthnDevices,
loginFromSession,
Expand Down
14 changes: 14 additions & 0 deletions src/main/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,20 @@ export type Consent = {
status: ConsentStatus
}

export type SessionDevice = {
id: string,
ip?: string,
operatingSystem?: string,
userAgentName?: string,
deviceClass?: string,
deviceName?: string,
firstConnection: string,
lastConnection: string
}

export type SessionDeviceListResponse = {
sessionDevices: SessionDevice[]
}
/**
* This type represents the settings of a ReachFive account's stored in the backend.
*/
Expand Down
8 changes: 7 additions & 1 deletion src/main/profileClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { CaptchaParams } from './captcha'
import type { HttpClient } from './httpClient'
import type { IdentityEventManager } from './identityEventManager'
import type { ApiClientConfig } from './main'
import { ApiClientConfig, SessionDeviceListResponse } from './main'
import type { OpenIdUser, Profile } from './models'

export type UpdateEmailParams = {
Expand Down Expand Up @@ -112,6 +112,7 @@ export default class ProfileClient {

private sendEmailVerificationUrl: string
private sendPhoneNumberVerificationUrl: string
private sessionDevicesUrl: string
private signupDataUrl: string
private unlinkUrl: string
private updateEmailUrl: string
Expand All @@ -129,6 +130,7 @@ export default class ProfileClient {

this.sendEmailVerificationUrl = '/send-email-verification'
this.sendPhoneNumberVerificationUrl = '/send-phone-number-verification'
this.sessionDevicesUrl = '/session-devices'
this.signupDataUrl = '/signup/data'
this.unlinkUrl = '/unlink'
this.updateEmailUrl = '/update-email'
Expand All @@ -140,6 +142,10 @@ export default class ProfileClient {
this.verifyEmailUrl = '/verify-email'
}

listSessionDevices(accessToken: string): Promise<SessionDeviceListResponse> {
return this.http.get<SessionDeviceListResponse>(this.sessionDevicesUrl, { accessToken })
}

getSignupData(signupToken: string): Promise<OpenIdUser> {
return this.http.get<OpenIdUser>(this.signupDataUrl, {
query: {
Expand Down