Skip to content

Commit

Permalink
feat: EXP add cross product identity matching (#1475)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris James <[email protected]>
  • Loading branch information
shineli1984 and cajames authored Feb 15, 2024
1 parent 837cb6c commit d6cc5cb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
8 changes: 7 additions & 1 deletion packages/internal/metrics/src/details.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { errorBoundary } from './utils/errorBoundary';
import { Detail } from './utils/constants';
import { storeDetail } from './utils/state';
import { storeDetail, getDetail as getDetailFn } from './utils/state';
import { getGlobalisedValue } from './utils/globalise';

const setEnvironmentFn = (env: 'sandbox' | 'production') => {
Expand All @@ -23,3 +23,9 @@ const setPublishableApiKeyFn = (publishableApiKey: string) => {
export const setPublishableApiKey = errorBoundary(
getGlobalisedValue('setPublishableApiKey', setPublishableApiKeyFn),
);

export const getDetail = errorBoundary(
getGlobalisedValue('getDetail', getDetailFn),
);

export { Detail };
2 changes: 2 additions & 0 deletions packages/internal/metrics/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ export {
setEnvironment,
setPassportClientId,
setPublishableApiKey,
getDetail,
Detail,
} from './details';
24 changes: 20 additions & 4 deletions packages/passport/sdk/src/authManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import axios from 'axios';
import DeviceCredentialsManager from 'storage/device_credentials_manager';
import * as crypto from 'crypto';
import jwt_decode from 'jwt-decode';
import { getDetail, Detail } from '@imtbl/metrics';
import { isTokenExpired } from './utils/token';
import { PassportErrorType, withPassportError } from './errors/passportError';
import {
Expand Down Expand Up @@ -153,10 +154,19 @@ export default class AuthManager {
});
};

public async login(): Promise<User> {
/**
* login
* @param anonymousId Caller can pass an anonymousId if they want to associate their user's identity with immutable's internal instrumentation.
*/
public async login(anonymousId?: string): Promise<User> {
return withPassportError<User>(async () => {
const rid = getDetail(Detail.RUNTIME_ID);
const popupWindowFeatures = { width: 410, height: 450 };
const oidcUser = await this.userManager.signinPopup({
extraQueryParams: {
rid: rid || '',
third_party_a_id: anonymousId || '',
},
popupWindowFeatures,
});

Expand All @@ -171,7 +181,11 @@ export default class AuthManager {
);
}

public async loginWithDeviceFlow(): Promise<DeviceConnectResponse> {
/**
* loginWithDeviceFlow
* @param anonymousId Caller can pass an anonymousId if they want to associate their user's identity with immutable's internal instrumentation.
*/
public async loginWithDeviceFlow(anonymousId?: string): Promise<DeviceConnectResponse> {
return withPassportError<DeviceConnectResponse>(async () => {
const response = await axios.post<DeviceCodeResponse>(
`${this.config.authenticationDomain}/oauth/device/code`,
Expand All @@ -183,10 +197,12 @@ export default class AuthManager {
formUrlEncodedHeader,
);

const rid = getDetail(Detail.RUNTIME_ID);

return {
code: response.data.user_code,
deviceCode: response.data.device_code,
url: response.data.verification_uri_complete,
url: `${response.data.verification_uri_complete}${rid ? `&rid=${rid}` : ''}${anonymousId ? `&third_party_a_id=${anonymousId}` : ''}`,
interval: response.data.interval,
};
}, PassportErrorType.AUTHENTICATION_ERROR);
Expand Down Expand Up @@ -338,7 +354,7 @@ export default class AuthManager {
return this.userManager.signoutSilentCallback(url);
}

public async forceUserRefresh() : Promise<User | null> {
public async forceUserRefresh(): Promise<User | null> {
return this.refreshTokenAndUpdatePromise();
}

Expand Down

0 comments on commit d6cc5cb

Please sign in to comment.