fix(core): honor OAuth attempt expiration (#37557)
This commit is contained in:
parent
fafb04ed59
commit
987242b3e8
4 changed files with 53 additions and 8 deletions
|
|
@ -70,6 +70,7 @@ export type Inputs = Integration.Inputs
|
|||
export type OAuthAuthorization = {
|
||||
readonly url: string
|
||||
readonly instructions: string
|
||||
readonly expiresAt?: number
|
||||
} & (
|
||||
| {
|
||||
readonly mode: "auto"
|
||||
|
|
@ -560,7 +561,7 @@ const layer = Layer.effect(
|
|||
)
|
||||
const id = AttemptID.create()
|
||||
const created = yield* Clock.currentTimeMillis
|
||||
const time = { created, expires: created + attemptLifetime }
|
||||
const time = { created, expires: authorization.expiresAt ?? created + attemptLifetime }
|
||||
yield* SynchronizedRef.update(attempts, (current) =>
|
||||
new Map(current).set(id, {
|
||||
status: "pending",
|
||||
|
|
|
|||
|
|
@ -133,12 +133,20 @@ const device = {
|
|||
},
|
||||
Device,
|
||||
).pipe(
|
||||
Effect.map((value) => ({
|
||||
mode: "auto" as const,
|
||||
url: value.verification_uri_complete ?? value.verification_uri,
|
||||
instructions: `Open ${value.verification_uri} on any device and enter code: ${value.user_code}`,
|
||||
callback: poll(value).pipe(Effect.flatMap((tokens) => credential(deviceMethodID, tokens))),
|
||||
})),
|
||||
Effect.flatMap((value) =>
|
||||
Clock.currentTimeMillis.pipe(
|
||||
Effect.map((created) => {
|
||||
const lifetime = positiveSeconds(value.expires_in, 0)
|
||||
return {
|
||||
mode: "auto" as const,
|
||||
url: value.verification_uri_complete ?? value.verification_uri,
|
||||
instructions: `Open ${value.verification_uri} on any device and enter code: ${value.user_code}`,
|
||||
...(lifetime ? { expiresAt: created + lifetime * 1000 } : {}),
|
||||
callback: poll(value).pipe(Effect.flatMap((tokens) => credential(deviceMethodID, tokens))),
|
||||
}
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
refresh: (value) => refresh(deviceMethodID, Credential.OAuth.make({ ...value, methodID: deviceMethodID })),
|
||||
} satisfies IntegrationOAuthMethodRegistration
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue