66import { asDateTimestampMs } from "../../shared/number-coercion.js" ;
77import { cloneAuthProfileStore } from "./clone.js" ;
88import { hasUsableOAuthCredential as hasUsableStoredOAuthCredential } from "./credential-state.js" ;
9+ import {
10+ isSafeToCopyOAuthIdentity ,
11+ normalizeAuthEmailToken ,
12+ normalizeAuthIdentityToken ,
13+ } from "./oauth-identity.js" ;
914import type { AuthProfileStore , OAuthCredential } from "./types.js" ;
1015
16+ export { normalizeAuthEmailToken , normalizeAuthIdentityToken } from "./oauth-identity.js" ;
17+
1118/** OAuth profile imported from a runtime external CLI source. */
1219export type RuntimeExternalOAuthProfile = {
1320 profileId : string ;
@@ -74,17 +81,6 @@ export function hasUsableOAuthCredential(
7481 return hasUsableStoredOAuthCredential ( credential , { now } ) ;
7582}
7683
77- /** Normalizes account identity tokens for equality checks. */
78- export function normalizeAuthIdentityToken ( value : string | undefined ) : string | undefined {
79- const trimmed = value ?. trim ( ) ;
80- return trimmed ? trimmed : undefined ;
81- }
82-
83- /** Normalizes auth email identity tokens for equality checks. */
84- export function normalizeAuthEmailToken ( value : string | undefined ) : string | undefined {
85- return normalizeAuthIdentityToken ( value ) ?. toLowerCase ( ) ;
86- }
87-
8884/** Returns true when an OAuth credential has account or email identity. */
8985export function hasOAuthIdentity (
9086 credential : Pick < OAuthCredential , "accountId" | "email" > ,
@@ -100,19 +96,7 @@ export function hasMatchingOAuthIdentity(
10096 existing : Pick < OAuthCredential , "accountId" | "email" > ,
10197 incoming : Pick < OAuthCredential , "accountId" | "email" > ,
10298) : boolean {
103- const existingAccountId = normalizeAuthIdentityToken ( existing . accountId ) ;
104- const incomingAccountId = normalizeAuthIdentityToken ( incoming . accountId ) ;
105- if ( existingAccountId !== undefined && incomingAccountId !== undefined ) {
106- return existingAccountId === incomingAccountId ;
107- }
108-
109- const existingEmail = normalizeAuthEmailToken ( existing . email ) ;
110- const incomingEmail = normalizeAuthEmailToken ( incoming . email ) ;
111- if ( existingEmail !== undefined && incomingEmail !== undefined ) {
112- return existingEmail === incomingEmail ;
113- }
114-
115- return false ;
99+ return hasOAuthIdentity ( existing ) && isSafeToCopyOAuthIdentity ( existing , incoming ) ;
116100}
117101
118102// Different adoption paths have different safety thresholds. Bootstrap can
0 commit comments