@yielded/auth 0.1.0-beta.4 → 0.1.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/DrizzleD1.d.mts +49 -0
- package/dist/DrizzleLibsql.d.mts +59 -10
- package/dist/DrizzleMysql2.d.mts +53 -4
- package/dist/DrizzlePglite.d.mts +53 -4
- package/dist/DrizzlePostgres.d.mts +51 -2
- package/dist/DrizzleSqliteBun.d.mts +53 -4
- package/dist/DrizzleSqliteDo.d.mts +59 -10
- package/dist/DrizzleSqliteNode.d.mts +53 -4
- package/dist/DrizzleSqliteWasm.d.mts +51 -2
- package/dist/GitHub.d.mts +2 -1
- package/dist/GitHub.mjs +2 -1
- package/dist/OpenIdClient.d.mts +2 -1
- package/dist/OpenIdClient.mjs +2 -1
- package/dist/drizzle/d1-oauth.d.mts +2 -2
- package/dist/drizzle/oauth-connected-state.d.mts +1 -1
- package/dist/drizzle/oauth-registration.d.mts +1 -1
- package/dist/drizzle/oauth-registration.mjs +3 -2
- package/dist/drizzle/oauth-registration.mjs.map +1 -1
- package/dist/oauth/OAuthConnectedRevocations.d.mts +10 -0
- package/dist/oauth/OAuthRegistrationIntents.d.mts +9 -0
- package/dist/oauth/accountsModels.d.mts +5 -0
- package/dist/oauth/connected.d.mts +22 -0
- package/dist/oauth/connectedModels.d.mts +115 -0
- package/dist/oauth/definition.d.mts +111 -3
- package/dist/oauth/github/identity.mjs +11 -9
- package/dist/oauth/github/identity.mjs.map +1 -1
- package/dist/oauth/github/profile.d.mts +61 -0
- package/dist/oauth/github/profile.mjs +72 -0
- package/dist/oauth/github/profile.mjs.map +1 -0
- package/dist/oauth/openid-client/connected/protocol.mjs +3 -0
- package/dist/oauth/openid-client/connected/protocol.mjs.map +1 -1
- package/dist/oauth/openid-client/profile.d.mts +39 -0
- package/dist/oauth/openid-client/profile.mjs +58 -0
- package/dist/oauth/openid-client/profile.mjs.map +1 -0
- package/dist/oauth/openid-client/protocol.mjs +3 -0
- package/dist/oauth/openid-client/protocol.mjs.map +1 -1
- package/dist/oauth/registrationModels.d.mts +22 -0
- package/dist/oauth/registrationModels.mjs +4 -1
- package/dist/oauth/registrationModels.mjs.map +1 -1
- package/dist/oauth/registrationSecrets.mjs +1 -0
- package/dist/oauth/registrationSecrets.mjs.map +1 -1
- package/dist/oauth/signInModels.d.mts +18 -0
- package/dist/oauth/signInModels.mjs +11 -1
- package/dist/oauth/signInModels.mjs.map +1 -1
- package/dist/oauth/signInModule.d.mts +43 -4
- package/dist/oauth/signInModule.mjs +1 -1
- package/dist/oauth/signInModule.mjs.map +1 -1
- package/dist/oauth/signInSnapshot.mjs +1 -1
- package/dist/oauth/signInSnapshot.mjs.map +1 -1
- package/package.json +1 -1
- package/src/GitHub.ts +1 -0
- package/src/OpenIdClient.ts +2 -0
- package/src/drizzle/oauth-registration.ts +4 -0
- package/src/oauth/github/identity.ts +11 -7
- package/src/oauth/github/profile.ts +64 -0
- package/src/oauth/openid-client/connected/protocol.ts +4 -0
- package/src/oauth/openid-client/profile.ts +68 -0
- package/src/oauth/openid-client/protocol.ts +4 -0
- package/src/oauth/registrationModels.ts +4 -0
- package/src/oauth/registrationSecrets.ts +1 -0
- package/src/oauth/signInModels.ts +18 -0
- package/src/oauth/signInModule.ts +4 -0
- package/src/oauth/signInSnapshot.ts +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.mjs","names":["M.OAuthConnectedProfile","M.OAuthConnectedConfiguration","M.OAuthConnectedTokenContext","M.OAuthConnectedTokenMaterial","M.OAuthConnectedScopes","M.OAuthConnectedGrantResponse"],"sources":["../../../../src/oauth/openid-client/connected/protocol.ts"],"sourcesContent":["import { Cause, DateTime, Effect, Layer, Redacted, Schema } from \"effect\";\nimport * as client from \"openid-client\";\n\nimport { reportAuthFailure } from \"../../../internal/diagnostics\";\nimport { RequestBindingFlowId } from \"../../../operations/requestBinding\";\nimport * as M from \"../../connectedModels\";\nimport { OAuthConnectedProtocol } from \"../../OAuthConnectedProtocol\";\nimport { OAuthProtocolRejected, OAuthUnavailable } from \"../../signInErrors\";\nimport {\n OAuthCallbackId,\n OAuthCodeResponse,\n OAuthDisplayProfile,\n OAuthExternalIdentity,\n OAuthInstant,\n OAuthProtocolPreparation,\n OAuthTransactionSecrets,\n} from \"../../signInModels\";\nimport { snapshotOAuth } from \"../../signInSnapshot\";\nimport {\n DefiniteTokenRejection,\n type ConnectedCompatibility,\n type ConnectedOptions,\n} from \"../compatibility\";\nimport { clientAuthentication } from \"../configuration\";\nimport { type OpenIdClientConfigurationError } from \"../models\";\nimport { ProviderRevocation } from \"../ProviderRevocation\";\nimport { boundedFetch } from \"../transport\";\nimport {\n installConnectedConfigurations,\n sameConnectedProfile,\n type InstalledConnectedProvider,\n} from \"./configuration\";\nimport type { OpenIdClientConnectedProtocolOptions } from \"./models\";\n\nconst unavailable = () => OAuthUnavailable.make({});\nconst rejected = () => OAuthProtocolRejected.make({});\n\nconst safe = <A, E, R>(effect: Effect.Effect<A, E, R>) =>\n effect.pipe(\n Effect.tapCause((cause) =>\n Cause.hasDies(cause) ? reportAuthFailure(\"oauth-protocol\", cause) : Effect.void,\n ),\n Effect.catchCause((cause): Effect.Effect<never, E | OAuthUnavailable> => {\n if (Cause.hasInterrupts(cause)) return Effect.interrupt;\n\n return Cause.hasDies(cause) ? Effect.fail(unavailable()) : Effect.failCause(cause);\n }),\n );\n\n/** After possible transmission, validation/transport failures remain ambiguous. */\nconst grantError = (error: unknown) =>\n error instanceof DefiniteTokenRejection ||\n (error instanceof client.ClientError && error.cause instanceof DefiniteTokenRejection) ||\n (error instanceof client.ResponseBodyError &&\n error.status === 400 &&\n error.error === \"invalid_grant\")\n ? rejected()\n : unavailable();\n\nconst prepareInput = Schema.Struct({\n profile: M.OAuthConnectedProfile,\n callbackId: OAuthCallbackId,\n flowId: RequestBindingFlowId,\n});\n\nconst prepareOutput = Schema.Struct({\n ...OAuthProtocolPreparation.fields,\n configuration: M.OAuthConnectedConfiguration,\n});\n\nconst exchangeInput = Schema.toType(\n Schema.Struct({\n configuration: M.OAuthConnectedConfiguration,\n secrets: OAuthTransactionSecrets,\n response: OAuthCodeResponse,\n verificationStartedAt: Schema.DateTimeUtcFromMillis,\n }),\n);\n\nconst refreshInput = Schema.toType(\n Schema.Struct({\n context: M.OAuthConnectedTokenContext,\n material: M.OAuthConnectedTokenMaterial,\n verificationStartedAt: Schema.DateTimeUtcFromMillis,\n }),\n);\n\nconst revokeInput = Schema.Struct({\n context: M.OAuthConnectedTokenContext,\n material: M.OAuthConnectedTokenMaterial,\n});\n\nconst numericDate = Schema.Finite.check(Schema.isBetween({ minimum: 0, maximum: 8640000000000 }));\n\nconst claimsSchema = Schema.Struct({\n iss: Schema.String,\n sub: OAuthExternalIdentity.fields.subject,\n aud: Schema.Union([\n Schema.String,\n Schema.Array(Schema.String).check(Schema.isMinLength(1), Schema.isMaxLength(1)),\n ]),\n azp: Schema.optionalKey(Schema.String),\n exp: numericDate,\n iat: numericDate,\n nbf: Schema.optionalKey(numericDate),\n auth_time: Schema.optionalKey(numericDate),\n nonce: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(256))),\n});\n\nconst identitySchema = Schema.Struct({\n subject: OAuthExternalIdentity.fields.subject,\n profile: Schema.optionalKey(OAuthDisplayProfile),\n});\n\nconst rawMetadataSchema = Schema.Struct({\n expires_in: Schema.optionalKey(Schema.Finite.check(Schema.isGreaterThan(0))),\n scope: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(16447))),\n});\n\nconst rawRefreshExpiry = Schema.UndefinedOr(Schema.Finite.check(Schema.isGreaterThanOrEqualTo(0)));\n\ninterface GrantMetadata {\n readonly expiresIn?: number;\n readonly scope?: string;\n readonly refreshExpiresIn?: number;\n}\n\nconst privateConfiguration = <R>(\n entry: InstalledConnectedProvider<R>,\n fetch: client.CustomFetch,\n timeout: number,\n signal: AbortSignal,\n purpose: \"grant\" | \"revoke\",\n compatibility?: ConnectedCompatibility,\n receipt?: Parameters<ConnectedCompatibility[\"inspectReceipt\"]>[1],\n) => {\n const provider = entry.provider;\n\n const authentication =\n purpose === \"revoke\" && provider.revocation.mode === \"rfc7009\"\n ? provider.revocation.authentication\n : provider.authentication;\n\n const configuration = new client.Configuration(\n entry.metadata,\n provider.clientId,\n {\n [client.clockSkew]: 0,\n [client.clockTolerance]: 0,\n ...(provider.protocol === \"oidc\" ? { id_token_signed_response_alg: \"RS256\" } : {}),\n },\n clientAuthentication(authentication),\n );\n\n const transport = boundedFetch(fetch, signal, entry.allowedUrls);\n let metadata: GrantMetadata | undefined;\n\n configuration.timeout = timeout;\n configuration[client.customFetch] = async (url, options) => {\n const response = await transport(url, options);\n\n if (\n purpose === \"grant\" &&\n url === new URL(entry.metadata.token_endpoint!).href &&\n (compatibility !== undefined || response.status === 200)\n ) {\n const body: unknown = await response.clone().json();\n\n signal.throwIfAborted();\n if (compatibility !== undefined) {\n if (!receipt) throw unavailable();\n compatibility.inspectReceipt(\n { body, status: response.status, contentType: response.headers.get(\"content-type\") },\n receipt,\n );\n signal.throwIfAborted();\n }\n if (response.status !== 200) return response;\n if (metadata !== undefined) throw unavailable();\n // oxlint-disable-next-line no-restricted-properties -- Capture bounded raw expiry values before the maintained parser's coercion.\n const decoded = Schema.decodeUnknownSync(rawMetadataSchema)(body);\n let refreshExpiresIn: number | undefined;\n\n if (provider.refreshExpiry !== \"unreported\") {\n // oxlint-disable-next-line no-restricted-properties -- The extension name and numeric semantics are explicitly installed.\n refreshExpiresIn = Schema.decodeUnknownSync(rawRefreshExpiry)(\n Reflect.get(body as object, provider.refreshExpiry.field),\n );\n if (refreshExpiresIn === 0 && provider.refreshExpiry.zero === \"unreported\")\n refreshExpiresIn = undefined;\n }\n metadata = {\n ...(decoded.expires_in === undefined ? {} : { expiresIn: decoded.expires_in }),\n ...(decoded.scope === undefined ? {} : { scope: decoded.scope }),\n ...(refreshExpiresIn === undefined ? {} : { refreshExpiresIn }),\n };\n }\n\n return response;\n };\n if (provider.protocol === \"oidc\") client.enableNonRepudiationChecks(configuration);\n\n return {\n configuration,\n metadata: () => {\n if (!metadata) throw unavailable();\n\n return metadata;\n },\n };\n};\n\nconst appendResources = (parameters: URLSearchParams, resources: ReadonlyArray<string>) => {\n for (const resource of resources) parameters.append(\"resource\", resource);\n};\n\nconst sameStrings = (left: ReadonlyArray<string>, right: ReadonlyArray<string>) =>\n left.length === right.length &&\n [...left].sort().every((value, index) => value === [...right].sort()[index]);\n\nexport const makeConnectedProtocolWithCompatibility = Effect.fn(\n \"makeOpenIdClientConnectedProtocol\",\n)(function* <R = never>(\n options: ConnectedOptions<R>,\n compatibility?: ConnectedCompatibility,\n): Effect.fn.Return<\n OAuthConnectedProtocol[\"Service\"],\n OpenIdClientConfigurationError | OAuthUnavailable,\n R | ProviderRevocation\n> {\n const decoderContext = yield* Effect.context<R>();\n const providerRevocation = yield* ProviderRevocation;\n\n const { installed, fetch, timeoutSeconds } = yield* installConnectedConfigurations(\n options,\n compatibility !== undefined,\n );\n\n const retained = Effect.fn(\"OpenIdClientConnected.retained\")(function* (\n saved: M.OAuthConnectedConfiguration,\n ) {\n const entry = installed.find(\n ({ provider }) =>\n provider.provider === saved.provider &&\n provider.configurationGeneration === saved.configurationGeneration,\n );\n\n const provider = entry?.provider;\n\n if (\n !entry ||\n !provider ||\n provider.protocol !== saved.protocol ||\n provider.issuer !== saved.issuer ||\n provider.responseIssuerMode !== saved.responseIssuerMode ||\n provider.clientRegistrationId !== saved.profile.clientRegistrationId ||\n !provider.profiles.some((profile) => sameConnectedProfile(profile, saved.profile)) ||\n provider.callbacks.find((callback) => callback.callbackId === saved.callbackId)\n ?.redirectUri !== saved.redirectUri\n )\n return yield* unavailable();\n\n return entry;\n });\n\n const checkedStart = Effect.fn(\"OpenIdClientConnected.startedAt\")(function* (\n start: DateTime.Utc,\n ) {\n const value = DateTime.toEpochMillis(start);\n\n if (\n !Number.isSafeInteger(value) ||\n value < 0 ||\n value > DateTime.toEpochMillis(yield* DateTime.now)\n )\n return yield* unavailable();\n\n return value;\n });\n\n const tokenMetadata = Effect.fn(\"OpenIdClientConnected.tokenMetadata\")(function* (\n profile: M.OAuthConnectedProfile,\n metadata: GrantMetadata,\n start: number,\n refreshRetained: boolean,\n ) {\n const scopes =\n compatibility !== undefined\n ? yield* Effect.try({\n try: () => compatibility.decodeScopes(metadata.scope, profile.scopes),\n catch: unavailable,\n })\n : metadata.scope === undefined\n ? profile.scopes\n : yield* Schema.decodeEffect(M.OAuthConnectedScopes)(metadata.scope.split(\" \")).pipe(\n Effect.mapError(unavailable),\n );\n\n if (new Set(scopes).size !== scopes.length || !sameStrings(scopes, profile.scopes))\n return yield* unavailable();\n\n const accessExpiresAtMillis =\n metadata.expiresIn === undefined\n ? undefined\n : yield* Schema.decodeEffect(OAuthInstant)(\n Math.floor(start + metadata.expiresIn * 1000),\n ).pipe(Effect.mapError(unavailable));\n\n const refreshExpiresAtMillis =\n !refreshRetained || metadata.refreshExpiresIn === undefined\n ? undefined\n : yield* Schema.decodeEffect(OAuthInstant)(\n Math.floor(start + metadata.refreshExpiresIn * 1000),\n ).pipe(Effect.mapError(unavailable));\n\n const now = DateTime.toEpochMillis(yield* DateTime.now);\n\n if (\n (accessExpiresAtMillis !== undefined && accessExpiresAtMillis <= now) ||\n (refreshExpiresAtMillis !== undefined && refreshExpiresAtMillis <= now)\n )\n return yield* unavailable();\n\n return {\n scopes: [...scopes],\n resources: [...profile.resources],\n ...(accessExpiresAtMillis === undefined ? {} : { accessExpiresAtMillis }),\n ...(refreshExpiresAtMillis === undefined ? {} : { refreshExpiresAtMillis }),\n };\n });\n\n const oidcIdentity = Effect.fn(\"OpenIdClientConnected.oidcIdentity\")(function* (\n entry: InstalledConnectedProvider<R>,\n raw: unknown,\n originalNonce: Redacted.Redacted<string>,\n previous?: {\n readonly identity: typeof OAuthExternalIdentity.Type;\n readonly continuation: Extract<\n M.OAuthConnectedTokenMaterial[\"continuation\"],\n { readonly _tag: \"Oidc\" }\n >;\n },\n ) {\n const provider = entry.provider;\n\n if (provider.protocol !== \"oidc\") return yield* unavailable();\n\n // oxlint-disable-next-line no-restricted-properties -- Project authenticated foreign ID-token claims into this narrower profile.\n const claims = yield* Schema.decodeUnknownEffect(claimsSchema)(raw).pipe(\n Effect.mapError(unavailable),\n );\n\n const now = DateTime.toEpochMillis(yield* DateTime.now) / 1000;\n const audience = typeof claims.aud === \"string\" ? claims.aud : claims.aud[0];\n\n if (\n claims.iss !== provider.issuer ||\n audience !== provider.clientId ||\n (claims.azp !== undefined && claims.azp !== provider.clientId) ||\n claims.exp <= now ||\n claims.iat > now ||\n (claims.nbf !== undefined && claims.nbf > now) ||\n (claims.auth_time !== undefined && claims.auth_time > now) ||\n (previous\n ? claims.sub !== previous.identity.subject ||\n (claims.nonce !== undefined && claims.nonce !== Redacted.value(originalNonce)) ||\n (claims.auth_time !== undefined && claims.auth_time !== previous.continuation.authTime)\n : claims.nonce !== Redacted.value(originalNonce) ||\n (provider.maxAgeSeconds !== undefined &&\n (claims.auth_time === undefined ||\n claims.auth_time + provider.maxAgeSeconds < Math.floor(now))))\n )\n return yield* unavailable();\n\n return {\n identity: { provider: provider.provider, issuer: provider.issuer, subject: claims.sub },\n continuation: previous?.continuation ?? {\n _tag: \"Oidc\" as const,\n clientId: provider.clientId,\n nonce: Redacted.make(Redacted.value(originalNonce)),\n ...(claims.auth_time === undefined ? {} : { authTime: claims.auth_time }),\n },\n };\n });\n\n const decodeIdentity = Effect.fn(\"OpenIdClientConnected.decodeIdentity\")(function* (\n entry: InstalledConnectedProvider<R>,\n body: unknown,\n ) {\n if (entry.provider.protocol !== \"oauth\") return yield* unavailable();\n const decoder = entry.provider.identitySource.decodeIdentity;\n\n const result = yield* Effect.suspend(() => decoder(body)).pipe(\n Effect.provideContext(decoderContext),\n Effect.catchCause((cause) => {\n const recovered = Cause.hasInterrupts(cause)\n ? Effect.interrupt\n : Effect.fail(unavailable());\n\n if (\n cause.reasons.length === 1 &&\n cause.reasons[0]?._tag === \"Fail\" &&\n Schema.is(OAuthProtocolRejected)(cause.reasons[0].error)\n )\n return recovered;\n\n return reportAuthFailure(\"oauth-identity\", cause).pipe(Effect.andThen(recovered));\n }),\n );\n\n const value = yield* Schema.decodeEffect(identitySchema)(result).pipe(\n Effect.mapError(unavailable),\n );\n\n return {\n identity: {\n provider: entry.provider.provider,\n issuer: entry.provider.issuer,\n subject: value.subject,\n },\n ...(value.profile === undefined ? {} : { profile: value.profile }),\n continuation: { _tag: \"OAuth\" as const },\n };\n });\n\n const prepareAuthorization: OAuthConnectedProtocol[\"Service\"][\"prepareAuthorization\"] = Effect.fn(\n \"OpenIdClientConnected.prepareAuthorization\",\n )(function* (input) {\n const request = yield* snapshotOAuth(prepareInput, input);\n\n const entry = installed.find(\n ({ provider }) =>\n provider.provider === request.profile.provider &&\n provider.issuance === \"active\" &&\n provider.profiles.some(\n (profile) =>\n profile.issuance === \"active\" && sameConnectedProfile(profile, request.profile),\n ),\n );\n\n const callback = entry?.provider.callbacks.find(\n (value) => value.callbackId === request.callbackId,\n );\n\n if (!entry || !callback || request.profile.issuance !== \"active\") return yield* rejected();\n\n const result = yield* Effect.tryPromise({\n try: async (signal) => {\n const { configuration } = privateConfiguration(\n entry,\n fetch,\n timeoutSeconds,\n signal,\n \"grant\",\n );\n\n const state = client.randomState(),\n verifier = client.randomPKCECodeVerifier(),\n nonce = entry.provider.protocol === \"oidc\" ? client.randomNonce() : undefined;\n\n const challenge = await client.calculatePKCECodeChallenge(verifier);\n\n signal.throwIfAborted();\n const parameters = new URLSearchParams(entry.provider.authorizationParameters);\n\n for (const [key, value] of Object.entries({\n response_type: \"code\",\n response_mode: \"query\",\n redirect_uri: callback.redirectUri,\n scope: (\n compatibility?.authorizationScopes(\n request.profile.scopes,\n request.profile.retention === \"access-and-refresh\",\n ) ?? request.profile.scopes\n ).join(\" \"),\n state,\n code_challenge: challenge,\n code_challenge_method: \"S256\",\n }))\n parameters.set(key, value);\n if (nonce !== undefined) parameters.set(\"nonce\", nonce);\n if (entry.provider.protocol === \"oidc\" && entry.provider.maxAgeSeconds !== undefined)\n parameters.set(\"max_age\", String(entry.provider.maxAgeSeconds));\n appendResources(parameters, request.profile.resources);\n\n return {\n configuration: {\n provider: entry.provider.provider,\n protocol: entry.provider.protocol,\n configurationGeneration: entry.provider.configurationGeneration,\n issuer: entry.provider.issuer,\n responseIssuerMode: entry.provider.responseIssuerMode,\n callbackId: callback.callbackId,\n redirectUri: callback.redirectUri,\n profile: request.profile,\n },\n authorizationUrl: Redacted.make(\n client.buildAuthorizationUrl(configuration, parameters).href,\n ),\n secrets: {\n namespace: \"effect-auth/oauth-transaction-secrets/v1\" as const,\n state: Redacted.make(state),\n pkceVerifier: Redacted.make(verifier),\n ...(nonce === undefined ? {} : { oidcNonce: Redacted.make(nonce) }),\n },\n };\n },\n catch: unavailable,\n });\n\n return yield* snapshotOAuth(prepareOutput, result);\n });\n\n const exchangeGrant: OAuthConnectedProtocol[\"Service\"][\"exchangeGrant\"] = Effect.fn(\n \"OpenIdClientConnected.exchangeGrant\",\n )(function* (input) {\n const request = yield* snapshotOAuth(exchangeInput, input),\n saved = request.configuration;\n\n const entry = yield* retained(saved),\n provider = entry.provider;\n\n if (\n (provider.protocol === \"oidc\") !== (request.secrets.oidcNonce !== undefined) ||\n Redacted.value(request.response.state) !== Redacted.value(request.secrets.state) ||\n (provider.responseIssuerMode === \"required\"\n ? request.response.issuer !== provider.issuer\n : request.response.issuer !== undefined)\n )\n return yield* rejected();\n const start = yield* checkedStart(request.verificationStartedAt);\n\n const result = yield* Effect.tryPromise({\n try: async (signal) => {\n const invocation = privateConfiguration(\n entry,\n fetch,\n timeoutSeconds,\n signal,\n \"grant\",\n compatibility,\n {\n scopes: saved.profile.scopes,\n refreshRequired: saved.profile.retention === \"access-and-refresh\",\n operation: \"authorization_code\",\n },\n );\n\n const url = new URL(saved.redirectUri);\n\n url.searchParams.set(\"code\", Redacted.value(request.response.code));\n url.searchParams.set(\"state\", Redacted.value(request.response.state));\n if (request.response.issuer !== undefined)\n url.searchParams.set(\"iss\", request.response.issuer);\n const parameters = new URLSearchParams(provider.tokenParameters);\n\n appendResources(parameters, saved.profile.resources);\n\n const tokens = await client.authorizationCodeGrant(\n invocation.configuration,\n url,\n {\n expectedState: Redacted.value(request.secrets.state),\n pkceCodeVerifier: Redacted.value(request.secrets.pkceVerifier),\n ...(provider.protocol === \"oidc\"\n ? {\n idTokenExpected: true,\n expectedNonce: Redacted.value(request.secrets.oidcNonce!),\n ...(provider.maxAgeSeconds === undefined\n ? {}\n : { maxAge: provider.maxAgeSeconds }),\n }\n : {}),\n },\n parameters,\n );\n\n signal.throwIfAborted();\n if (tokens.token_type !== \"bearer\") throw unavailable();\n const metadata = invocation.metadata();\n let body: unknown;\n\n if (provider.protocol === \"oauth\") {\n const response = await client.fetchProtectedResource(\n invocation.configuration,\n tokens.access_token,\n new URL(provider.identitySource.url),\n \"GET\",\n undefined,\n new Headers(provider.identitySource.headers),\n );\n\n signal.throwIfAborted();\n if (\n response.status !== 200 ||\n response.headers.get(\"content-type\")?.split(\";\", 1)[0]?.trim().toLowerCase() !==\n \"application/json\"\n )\n throw unavailable();\n body = await response.json();\n signal.throwIfAborted();\n }\n\n return {\n tokens,\n metadata,\n body,\n };\n },\n catch: grantError,\n });\n\n const identity =\n provider.protocol === \"oidc\"\n ? yield* oidcIdentity(entry, result.tokens.claims(), request.secrets.oidcNonce!)\n : yield* decodeIdentity(entry, result.body);\n\n const refreshToken =\n saved.profile.retention === \"access-and-refresh\" ? result.tokens.refresh_token : undefined;\n\n const metadata = yield* tokenMetadata(\n saved.profile,\n result.metadata,\n start,\n refreshToken !== undefined,\n );\n\n return yield* snapshotOAuth(M.OAuthConnectedGrantResponse, {\n ...identity,\n ...metadata,\n material: {\n namespace: \"effect-auth/oauth-connected-token-material/v1\",\n accessToken: Redacted.make(result.tokens.access_token),\n ...(refreshToken === undefined ? {} : { refreshToken: Redacted.make(refreshToken) }),\n continuation: identity.continuation,\n },\n });\n });\n\n const refreshGrant: OAuthConnectedProtocol[\"Service\"][\"refreshGrant\"] = Effect.fn(\n \"OpenIdClientConnected.refreshGrant\",\n )(function* (input) {\n const request = yield* snapshotOAuth(refreshInput, input),\n saved = request.context.configuration;\n\n const entry = yield* retained(saved),\n provider = entry.provider,\n previous = request.material.continuation;\n\n if (\n saved.profile.retention !== \"access-and-refresh\" ||\n saved.profile.refresh === \"unsupported\" ||\n !request.material.refreshToken ||\n request.context.identity.provider !== provider.provider ||\n request.context.identity.issuer !== provider.issuer ||\n (provider.protocol === \"oidc\"\n ? previous._tag !== \"Oidc\" ||\n previous.clientId !== provider.clientId ||\n previous.nonce === undefined\n : previous._tag !== \"OAuth\") ||\n !sameStrings(request.context.metadata.scopes, saved.profile.scopes) ||\n !sameStrings(request.context.metadata.resources, saved.profile.resources)\n )\n return yield* unavailable();\n const start = yield* checkedStart(request.verificationStartedAt);\n\n if (\n (request.context.metadata.refreshUseUntilMillis !== undefined &&\n request.context.metadata.refreshUseUntilMillis <= start) ||\n (request.context.metadata.refreshExpiresAtMillis !== undefined &&\n request.context.metadata.refreshExpiresAtMillis <= start)\n )\n return yield* unavailable();\n\n const result = yield* Effect.tryPromise({\n try: async (signal) => {\n const invocation = privateConfiguration(\n entry,\n fetch,\n timeoutSeconds,\n signal,\n \"grant\",\n compatibility,\n {\n scopes: saved.profile.scopes,\n refreshRequired: true,\n operation: \"refresh_token\",\n },\n );\n\n const parameters = new URLSearchParams(provider.refreshParameters);\n\n if (compatibility?.includeRefreshScope !== false)\n parameters.set(\"scope\", saved.profile.scopes.join(\" \"));\n appendResources(parameters, saved.profile.resources);\n\n const tokens = await client.refreshTokenGrant(\n invocation.configuration,\n Redacted.value(request.material.refreshToken!),\n parameters,\n );\n\n signal.throwIfAborted();\n if (\n tokens.token_type !== \"bearer\" ||\n (saved.profile.refresh === \"rotating\" &&\n (!tokens.refresh_token ||\n tokens.refresh_token === Redacted.value(request.material.refreshToken!)))\n )\n throw unavailable();\n const metadata = invocation.metadata();\n let body: unknown;\n\n if (provider.protocol === \"oauth\") {\n const response = await client.fetchProtectedResource(\n invocation.configuration,\n tokens.access_token,\n new URL(provider.identitySource.url),\n \"GET\",\n undefined,\n new Headers(provider.identitySource.headers),\n );\n\n signal.throwIfAborted();\n if (\n response.status !== 200 ||\n response.headers.get(\"content-type\")?.split(\";\", 1)[0]?.trim().toLowerCase() !==\n \"application/json\"\n )\n throw unavailable();\n body = await response.json();\n signal.throwIfAborted();\n }\n\n return {\n tokens,\n metadata,\n body,\n };\n },\n catch: grantError,\n });\n\n if (provider.protocol === \"oidc\") {\n if (previous._tag !== \"Oidc\" || !previous.nonce) return yield* unavailable();\n if (result.tokens.id_token !== undefined)\n yield* oidcIdentity(entry, result.tokens.claims(), previous.nonce, {\n identity: request.context.identity,\n continuation: previous,\n });\n } else {\n const identity = yield* decodeIdentity(entry, result.body);\n\n if (identity.identity.subject !== request.context.identity.subject)\n return yield* unavailable();\n }\n const metadata = yield* tokenMetadata(saved.profile, result.metadata, start, true);\n const finishedAt = DateTime.toEpochMillis(yield* DateTime.now);\n\n if (\n (request.context.metadata.refreshUseUntilMillis !== undefined &&\n request.context.metadata.refreshUseUntilMillis <= finishedAt) ||\n (request.context.metadata.refreshExpiresAtMillis !== undefined &&\n request.context.metadata.refreshExpiresAtMillis <= finishedAt)\n )\n return yield* unavailable();\n\n return yield* snapshotOAuth(M.OAuthConnectedGrantResponse, {\n identity: request.context.identity,\n ...metadata,\n material: {\n namespace: \"effect-auth/oauth-connected-token-material/v1\",\n accessToken: Redacted.make(result.tokens.access_token),\n ...(result.tokens.refresh_token === undefined\n ? {}\n : { refreshToken: Redacted.make(result.tokens.refresh_token) }),\n continuation: previous,\n },\n });\n });\n\n const revokeGrant: OAuthConnectedProtocol[\"Service\"][\"revokeGrant\"] = Effect.fn(\n \"OpenIdClientConnected.revokeGrant\",\n )(function* (input) {\n const request = yield* snapshotOAuth(revokeInput, input),\n saved = request.context.configuration;\n\n const entry = yield* retained(saved),\n revocation = entry.provider.revocation;\n\n if (\n saved.profile.revocation !== \"cohort\" ||\n revocation.mode === \"unsupported\" ||\n (revocation.mode === \"provider-cohort\" && compatibility === undefined) ||\n (revocation.mode === \"rfc7009\" &&\n request.material.refreshToken !== undefined &&\n revocation.tokenTypes !== \"access-and-refresh\") ||\n request.context.identity.provider !== entry.provider.provider ||\n request.context.identity.issuer !== entry.provider.issuer ||\n (entry.provider.protocol === \"oidc\"\n ? request.material.continuation._tag !== \"Oidc\" ||\n request.material.continuation.clientId !== entry.provider.clientId\n : request.material.continuation._tag !== \"OAuth\")\n )\n return yield* unavailable();\n if (revocation.mode === \"provider-cohort\") {\n yield* providerRevocation.revoke({\n clientId: entry.provider.clientId,\n authentication: entry.provider.authentication,\n context: request.context,\n material: request.material,\n });\n\n return \"Confirmed\" as const;\n }\n yield* Effect.tryPromise({\n try: async (signal) => {\n const { configuration } = privateConfiguration(\n entry,\n fetch,\n timeoutSeconds,\n signal,\n \"revoke\",\n );\n\n if (request.material.refreshToken !== undefined) {\n await client.tokenRevocation(\n configuration,\n Redacted.value(request.material.refreshToken),\n { token_type_hint: \"refresh_token\" },\n );\n signal.throwIfAborted();\n }\n await client.tokenRevocation(configuration, Redacted.value(request.material.accessToken), {\n token_type_hint: \"access_token\",\n });\n signal.throwIfAborted();\n },\n catch: unavailable,\n });\n\n return \"Confirmed\" as const;\n });\n\n return OAuthConnectedProtocol.of({\n prepareAuthorization: (input) => safe(prepareAuthorization(input)),\n exchangeGrant: (input) => safe(exchangeGrant(input)),\n refreshGrant: (input) => safe(refreshGrant(input)),\n revokeGrant: (input) => safe(revokeGrant(input)),\n });\n}, safe);\n\nexport const makeOpenIdClientConnectedProtocol = <R = never>(\n options: OpenIdClientConnectedProtocolOptions<R>,\n): Effect.Effect<\n OAuthConnectedProtocol[\"Service\"],\n OpenIdClientConfigurationError | OAuthUnavailable,\n R\n> =>\n makeConnectedProtocolWithCompatibility(options).pipe(\n Effect.provide(ProviderRevocation.layerUnsupported),\n );\n\nexport const openIdClientConnectedProtocolLayer = <R = never>(\n options: OpenIdClientConnectedProtocolOptions<R>,\n) => Layer.effect(OAuthConnectedProtocol, makeOpenIdClientConnectedProtocol(options));\n"],"mappings":";;;;;;;;;;;;;;;AAkCA,MAAM,oBAAoB,iBAAiB,KAAK,CAAC,CAAC;AAClD,MAAM,iBAAiB,sBAAsB,KAAK,CAAC,CAAC;AAEpD,MAAM,QAAiB,WACrB,OAAO,KACL,OAAO,UAAU,UACf,MAAM,QAAQ,KAAK,IAAI,kBAAkB,kBAAkB,KAAK,IAAI,OAAO,IAC7E,GACA,OAAO,YAAY,UAAsD;CACvE,IAAI,MAAM,cAAc,KAAK,GAAG,OAAO,OAAO;CAE9C,OAAO,MAAM,QAAQ,KAAK,IAAI,OAAO,KAAK,YAAY,CAAC,IAAI,OAAO,UAAU,KAAK;AACnF,CAAC,CACH;;AAGF,MAAM,cAAc,UAClB,iBAAiB,0BAChB,iBAAiB,OAAO,eAAe,MAAM,iBAAiB,0BAC9D,iBAAiB,OAAO,qBACvB,MAAM,WAAW,OACjB,MAAM,UAAU,kBACd,SAAS,IACT,YAAY;AAElB,MAAM,eAAe,OAAO,OAAO;CACjC,SAASA;CACT,YAAY;CACZ,QAAQ;AACV,CAAC;AAED,MAAM,gBAAgB,OAAO,OAAO;CAClC,GAAG,yBAAyB;CAC5B,eAAeC;AACjB,CAAC;AAED,MAAM,gBAAgB,OAAO,OAC3B,OAAO,OAAO;CACZ,eAAeA;CACf,SAAS;CACT,UAAU;CACV,uBAAuB,OAAO;AAChC,CAAC,CACH;AAEA,MAAM,eAAe,OAAO,OAC1B,OAAO,OAAO;CACZ,SAASC;CACT,UAAUC;CACV,uBAAuB,OAAO;AAChC,CAAC,CACH;AAEA,MAAM,cAAc,OAAO,OAAO;CAChC,SAASD;CACT,UAAUC;AACZ,CAAC;AAED,MAAM,cAAc,OAAO,OAAO,MAAM,OAAO,UAAU;CAAE,SAAS;CAAG,SAAS;AAAc,CAA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1D,QAAQ,SAAS,aAAa,SAAS,UAE3C,OAAO,OAAO,YAAY;EAC5B,IAAI,WAAW,SAAS,mBAAmB;GACzC,OAAO,mBAAmB,OAAO;IAC/B,UAAU,MAAM,SAAS;IACzB,gBAAgB,MAAM,SAAS;IAC/B,SAAS,QAAQ;IACjB,UAAU,QAAQ;GACpB,CAAC;GAED,OAAO;EACT;EACA,OAAO,OAAO,WAAW;GACvB,KAAK,OAAO,WAAW;IACrB,MAAM,EAAE,kBAAkB,qBACxB,OACA,OACA,gBACA,QACA,QACF;IAEA,IAAI,QAAQ,SAAS,iBAAiB,KAAA,GAAW;KAC/C,MAAM,OAAO,gBACX,eACA,SAAS,MAAM,QAAQ,SAAS,YAAY,GAC5C,EAAE,iBAAiB,gBAAgB,CACrC;KACA,OAAO,eAAe;IACxB;IACA,MAAM,OAAO,gBAAgB,eAAe,SAAS,MAAM,QAAQ,SAAS,WAAW,GAAG,EACxF,iBAAiB,eACnB,CAAC;IACD,OAAO,eAAe;GACxB;GACA,OAAO;EACT,CAAC;EAED,OAAO;CACT,CAAC;CAED,OAAO,uBAAuB,GAAG;EAC/B,uBAAuB,UAAU,KAAK,qBAAqB,KAAK,CAAC;EACjE,gBAAgB,UAAU,KAAK,cAAc,KAAK,CAAC;EACnD,eAAe,UAAU,KAAK,aAAa,KAAK,CAAC;EACjD,cAAc,UAAU,KAAK,YAAY,KAAK,CAAC;CACjD,CAAC;AACH,GAAG,IAAI;AAEP,MAAa,qCACX,YAMA,uCAAuC,OAAO,CAAC,CAAC,KAC9C,OAAO,QAAQ,mBAAmB,gBAAgB,CACpD;AAEF,MAAa,sCACX,YACG,MAAM,OAAO,wBAAwB,kCAAkC,OAAO,CAAC"}
|
|
1
|
+
{"version":3,"file":"protocol.mjs","names":["M.OAuthConnectedProfile","M.OAuthConnectedConfiguration","M.OAuthConnectedTokenContext","M.OAuthConnectedTokenMaterial","M.OAuthConnectedScopes","M.OAuthConnectedGrantResponse"],"sources":["../../../../src/oauth/openid-client/connected/protocol.ts"],"sourcesContent":["import { Cause, DateTime, Effect, Layer, Redacted, Schema } from \"effect\";\nimport * as client from \"openid-client\";\n\nimport { reportAuthFailure } from \"../../../internal/diagnostics\";\nimport { RequestBindingFlowId } from \"../../../operations/requestBinding\";\nimport * as M from \"../../connectedModels\";\nimport { OAuthConnectedProtocol } from \"../../OAuthConnectedProtocol\";\nimport { OAuthProtocolRejected, OAuthUnavailable } from \"../../signInErrors\";\nimport {\n OAuthCallbackId,\n OAuthCodeResponse,\n OAuthDisplayProfile,\n OAuthExternalIdentity,\n OAuthInstant,\n OAuthProtocolPreparation,\n OAuthTransactionSecrets,\n} from \"../../signInModels\";\nimport { snapshotOAuth } from \"../../signInSnapshot\";\nimport {\n DefiniteTokenRejection,\n type ConnectedCompatibility,\n type ConnectedOptions,\n} from \"../compatibility\";\nimport { clientAuthentication } from \"../configuration\";\nimport { type OpenIdClientConfigurationError } from \"../models\";\nimport { decodeOidcProfile } from \"../profile\";\nimport { ProviderRevocation } from \"../ProviderRevocation\";\nimport { boundedFetch } from \"../transport\";\nimport {\n installConnectedConfigurations,\n sameConnectedProfile,\n type InstalledConnectedProvider,\n} from \"./configuration\";\nimport type { OpenIdClientConnectedProtocolOptions } from \"./models\";\n\nconst unavailable = () => OAuthUnavailable.make({});\nconst rejected = () => OAuthProtocolRejected.make({});\n\nconst safe = <A, E, R>(effect: Effect.Effect<A, E, R>) =>\n effect.pipe(\n Effect.tapCause((cause) =>\n Cause.hasDies(cause) ? reportAuthFailure(\"oauth-protocol\", cause) : Effect.void,\n ),\n Effect.catchCause((cause): Effect.Effect<never, E | OAuthUnavailable> => {\n if (Cause.hasInterrupts(cause)) return Effect.interrupt;\n\n return Cause.hasDies(cause) ? Effect.fail(unavailable()) : Effect.failCause(cause);\n }),\n );\n\n/** After possible transmission, validation/transport failures remain ambiguous. */\nconst grantError = (error: unknown) =>\n error instanceof DefiniteTokenRejection ||\n (error instanceof client.ClientError && error.cause instanceof DefiniteTokenRejection) ||\n (error instanceof client.ResponseBodyError &&\n error.status === 400 &&\n error.error === \"invalid_grant\")\n ? rejected()\n : unavailable();\n\nconst prepareInput = Schema.Struct({\n profile: M.OAuthConnectedProfile,\n callbackId: OAuthCallbackId,\n flowId: RequestBindingFlowId,\n});\n\nconst prepareOutput = Schema.Struct({\n ...OAuthProtocolPreparation.fields,\n configuration: M.OAuthConnectedConfiguration,\n});\n\nconst exchangeInput = Schema.toType(\n Schema.Struct({\n configuration: M.OAuthConnectedConfiguration,\n secrets: OAuthTransactionSecrets,\n response: OAuthCodeResponse,\n verificationStartedAt: Schema.DateTimeUtcFromMillis,\n }),\n);\n\nconst refreshInput = Schema.toType(\n Schema.Struct({\n context: M.OAuthConnectedTokenContext,\n material: M.OAuthConnectedTokenMaterial,\n verificationStartedAt: Schema.DateTimeUtcFromMillis,\n }),\n);\n\nconst revokeInput = Schema.Struct({\n context: M.OAuthConnectedTokenContext,\n material: M.OAuthConnectedTokenMaterial,\n});\n\nconst numericDate = Schema.Finite.check(Schema.isBetween({ minimum: 0, maximum: 8640000000000 }));\n\nconst claimsSchema = Schema.Struct({\n iss: Schema.String,\n sub: OAuthExternalIdentity.fields.subject,\n aud: Schema.Union([\n Schema.String,\n Schema.Array(Schema.String).check(Schema.isMinLength(1), Schema.isMaxLength(1)),\n ]),\n azp: Schema.optionalKey(Schema.String),\n exp: numericDate,\n iat: numericDate,\n nbf: Schema.optionalKey(numericDate),\n auth_time: Schema.optionalKey(numericDate),\n nonce: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(256))),\n});\n\nconst identitySchema = Schema.Struct({\n subject: OAuthExternalIdentity.fields.subject,\n profile: Schema.optionalKey(OAuthDisplayProfile),\n});\n\nconst rawMetadataSchema = Schema.Struct({\n expires_in: Schema.optionalKey(Schema.Finite.check(Schema.isGreaterThan(0))),\n scope: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(16447))),\n});\n\nconst rawRefreshExpiry = Schema.UndefinedOr(Schema.Finite.check(Schema.isGreaterThanOrEqualTo(0)));\n\ninterface GrantMetadata {\n readonly expiresIn?: number;\n readonly scope?: string;\n readonly refreshExpiresIn?: number;\n}\n\nconst privateConfiguration = <R>(\n entry: InstalledConnectedProvider<R>,\n fetch: client.CustomFetch,\n timeout: number,\n signal: AbortSignal,\n purpose: \"grant\" | \"revoke\",\n compatibility?: ConnectedCompatibility,\n receipt?: Parameters<ConnectedCompatibility[\"inspectReceipt\"]>[1],\n) => {\n const provider = entry.provider;\n\n const authentication =\n purpose === \"revoke\" && provider.revocation.mode === \"rfc7009\"\n ? provider.revocation.authentication\n : provider.authentication;\n\n const configuration = new client.Configuration(\n entry.metadata,\n provider.clientId,\n {\n [client.clockSkew]: 0,\n [client.clockTolerance]: 0,\n ...(provider.protocol === \"oidc\" ? { id_token_signed_response_alg: \"RS256\" } : {}),\n },\n clientAuthentication(authentication),\n );\n\n const transport = boundedFetch(fetch, signal, entry.allowedUrls);\n let metadata: GrantMetadata | undefined;\n\n configuration.timeout = timeout;\n configuration[client.customFetch] = async (url, options) => {\n const response = await transport(url, options);\n\n if (\n purpose === \"grant\" &&\n url === new URL(entry.metadata.token_endpoint!).href &&\n (compatibility !== undefined || response.status === 200)\n ) {\n const body: unknown = await response.clone().json();\n\n signal.throwIfAborted();\n if (compatibility !== undefined) {\n if (!receipt) throw unavailable();\n compatibility.inspectReceipt(\n { body, status: response.status, contentType: response.headers.get(\"content-type\") },\n receipt,\n );\n signal.throwIfAborted();\n }\n if (response.status !== 200) return response;\n if (metadata !== undefined) throw unavailable();\n // oxlint-disable-next-line no-restricted-properties -- Capture bounded raw expiry values before the maintained parser's coercion.\n const decoded = Schema.decodeUnknownSync(rawMetadataSchema)(body);\n let refreshExpiresIn: number | undefined;\n\n if (provider.refreshExpiry !== \"unreported\") {\n // oxlint-disable-next-line no-restricted-properties -- The extension name and numeric semantics are explicitly installed.\n refreshExpiresIn = Schema.decodeUnknownSync(rawRefreshExpiry)(\n Reflect.get(body as object, provider.refreshExpiry.field),\n );\n if (refreshExpiresIn === 0 && provider.refreshExpiry.zero === \"unreported\")\n refreshExpiresIn = undefined;\n }\n metadata = {\n ...(decoded.expires_in === undefined ? {} : { expiresIn: decoded.expires_in }),\n ...(decoded.scope === undefined ? {} : { scope: decoded.scope }),\n ...(refreshExpiresIn === undefined ? {} : { refreshExpiresIn }),\n };\n }\n\n return response;\n };\n if (provider.protocol === \"oidc\") client.enableNonRepudiationChecks(configuration);\n\n return {\n configuration,\n metadata: () => {\n if (!metadata) throw unavailable();\n\n return metadata;\n },\n };\n};\n\nconst appendResources = (parameters: URLSearchParams, resources: ReadonlyArray<string>) => {\n for (const resource of resources) parameters.append(\"resource\", resource);\n};\n\nconst sameStrings = (left: ReadonlyArray<string>, right: ReadonlyArray<string>) =>\n left.length === right.length &&\n [...left].sort().every((value, index) => value === [...right].sort()[index]);\n\nexport const makeConnectedProtocolWithCompatibility = Effect.fn(\n \"makeOpenIdClientConnectedProtocol\",\n)(function* <R = never>(\n options: ConnectedOptions<R>,\n compatibility?: ConnectedCompatibility,\n): Effect.fn.Return<\n OAuthConnectedProtocol[\"Service\"],\n OpenIdClientConfigurationError | OAuthUnavailable,\n R | ProviderRevocation\n> {\n const decoderContext = yield* Effect.context<R>();\n const providerRevocation = yield* ProviderRevocation;\n\n const { installed, fetch, timeoutSeconds } = yield* installConnectedConfigurations(\n options,\n compatibility !== undefined,\n );\n\n const retained = Effect.fn(\"OpenIdClientConnected.retained\")(function* (\n saved: M.OAuthConnectedConfiguration,\n ) {\n const entry = installed.find(\n ({ provider }) =>\n provider.provider === saved.provider &&\n provider.configurationGeneration === saved.configurationGeneration,\n );\n\n const provider = entry?.provider;\n\n if (\n !entry ||\n !provider ||\n provider.protocol !== saved.protocol ||\n provider.issuer !== saved.issuer ||\n provider.responseIssuerMode !== saved.responseIssuerMode ||\n provider.clientRegistrationId !== saved.profile.clientRegistrationId ||\n !provider.profiles.some((profile) => sameConnectedProfile(profile, saved.profile)) ||\n provider.callbacks.find((callback) => callback.callbackId === saved.callbackId)\n ?.redirectUri !== saved.redirectUri\n )\n return yield* unavailable();\n\n return entry;\n });\n\n const checkedStart = Effect.fn(\"OpenIdClientConnected.startedAt\")(function* (\n start: DateTime.Utc,\n ) {\n const value = DateTime.toEpochMillis(start);\n\n if (\n !Number.isSafeInteger(value) ||\n value < 0 ||\n value > DateTime.toEpochMillis(yield* DateTime.now)\n )\n return yield* unavailable();\n\n return value;\n });\n\n const tokenMetadata = Effect.fn(\"OpenIdClientConnected.tokenMetadata\")(function* (\n profile: M.OAuthConnectedProfile,\n metadata: GrantMetadata,\n start: number,\n refreshRetained: boolean,\n ) {\n const scopes =\n compatibility !== undefined\n ? yield* Effect.try({\n try: () => compatibility.decodeScopes(metadata.scope, profile.scopes),\n catch: unavailable,\n })\n : metadata.scope === undefined\n ? profile.scopes\n : yield* Schema.decodeEffect(M.OAuthConnectedScopes)(metadata.scope.split(\" \")).pipe(\n Effect.mapError(unavailable),\n );\n\n if (new Set(scopes).size !== scopes.length || !sameStrings(scopes, profile.scopes))\n return yield* unavailable();\n\n const accessExpiresAtMillis =\n metadata.expiresIn === undefined\n ? undefined\n : yield* Schema.decodeEffect(OAuthInstant)(\n Math.floor(start + metadata.expiresIn * 1000),\n ).pipe(Effect.mapError(unavailable));\n\n const refreshExpiresAtMillis =\n !refreshRetained || metadata.refreshExpiresIn === undefined\n ? undefined\n : yield* Schema.decodeEffect(OAuthInstant)(\n Math.floor(start + metadata.refreshExpiresIn * 1000),\n ).pipe(Effect.mapError(unavailable));\n\n const now = DateTime.toEpochMillis(yield* DateTime.now);\n\n if (\n (accessExpiresAtMillis !== undefined && accessExpiresAtMillis <= now) ||\n (refreshExpiresAtMillis !== undefined && refreshExpiresAtMillis <= now)\n )\n return yield* unavailable();\n\n return {\n scopes: [...scopes],\n resources: [...profile.resources],\n ...(accessExpiresAtMillis === undefined ? {} : { accessExpiresAtMillis }),\n ...(refreshExpiresAtMillis === undefined ? {} : { refreshExpiresAtMillis }),\n };\n });\n\n const oidcIdentity = Effect.fn(\"OpenIdClientConnected.oidcIdentity\")(function* (\n entry: InstalledConnectedProvider<R>,\n raw: unknown,\n originalNonce: Redacted.Redacted<string>,\n previous?: {\n readonly identity: typeof OAuthExternalIdentity.Type;\n readonly continuation: Extract<\n M.OAuthConnectedTokenMaterial[\"continuation\"],\n { readonly _tag: \"Oidc\" }\n >;\n },\n ) {\n const provider = entry.provider;\n\n if (provider.protocol !== \"oidc\") return yield* unavailable();\n\n // oxlint-disable-next-line no-restricted-properties -- Project authenticated foreign ID-token claims into this narrower profile.\n const claims = yield* Schema.decodeUnknownEffect(claimsSchema)(raw).pipe(\n Effect.mapError(unavailable),\n );\n\n const now = DateTime.toEpochMillis(yield* DateTime.now) / 1000;\n const audience = typeof claims.aud === \"string\" ? claims.aud : claims.aud[0];\n\n if (\n claims.iss !== provider.issuer ||\n audience !== provider.clientId ||\n (claims.azp !== undefined && claims.azp !== provider.clientId) ||\n claims.exp <= now ||\n claims.iat > now ||\n (claims.nbf !== undefined && claims.nbf > now) ||\n (claims.auth_time !== undefined && claims.auth_time > now) ||\n (previous\n ? claims.sub !== previous.identity.subject ||\n (claims.nonce !== undefined && claims.nonce !== Redacted.value(originalNonce)) ||\n (claims.auth_time !== undefined && claims.auth_time !== previous.continuation.authTime)\n : claims.nonce !== Redacted.value(originalNonce) ||\n (provider.maxAgeSeconds !== undefined &&\n (claims.auth_time === undefined ||\n claims.auth_time + provider.maxAgeSeconds < Math.floor(now))))\n )\n return yield* unavailable();\n\n const profile = yield* decodeOidcProfile(raw).pipe(Effect.mapError(unavailable));\n\n return {\n identity: { provider: provider.provider, issuer: provider.issuer, subject: claims.sub },\n ...(profile === undefined ? {} : { profile }),\n continuation: previous?.continuation ?? {\n _tag: \"Oidc\" as const,\n clientId: provider.clientId,\n nonce: Redacted.make(Redacted.value(originalNonce)),\n ...(claims.auth_time === undefined ? {} : { authTime: claims.auth_time }),\n },\n };\n });\n\n const decodeIdentity = Effect.fn(\"OpenIdClientConnected.decodeIdentity\")(function* (\n entry: InstalledConnectedProvider<R>,\n body: unknown,\n ) {\n if (entry.provider.protocol !== \"oauth\") return yield* unavailable();\n const decoder = entry.provider.identitySource.decodeIdentity;\n\n const result = yield* Effect.suspend(() => decoder(body)).pipe(\n Effect.provideContext(decoderContext),\n Effect.catchCause((cause) => {\n const recovered = Cause.hasInterrupts(cause)\n ? Effect.interrupt\n : Effect.fail(unavailable());\n\n if (\n cause.reasons.length === 1 &&\n cause.reasons[0]?._tag === \"Fail\" &&\n Schema.is(OAuthProtocolRejected)(cause.reasons[0].error)\n )\n return recovered;\n\n return reportAuthFailure(\"oauth-identity\", cause).pipe(Effect.andThen(recovered));\n }),\n );\n\n const value = yield* Schema.decodeEffect(identitySchema)(result).pipe(\n Effect.mapError(unavailable),\n );\n\n return {\n identity: {\n provider: entry.provider.provider,\n issuer: entry.provider.issuer,\n subject: value.subject,\n },\n ...(value.profile === undefined ? {} : { profile: value.profile }),\n continuation: { _tag: \"OAuth\" as const },\n };\n });\n\n const prepareAuthorization: OAuthConnectedProtocol[\"Service\"][\"prepareAuthorization\"] = Effect.fn(\n \"OpenIdClientConnected.prepareAuthorization\",\n )(function* (input) {\n const request = yield* snapshotOAuth(prepareInput, input);\n\n const entry = installed.find(\n ({ provider }) =>\n provider.provider === request.profile.provider &&\n provider.issuance === \"active\" &&\n provider.profiles.some(\n (profile) =>\n profile.issuance === \"active\" && sameConnectedProfile(profile, request.profile),\n ),\n );\n\n const callback = entry?.provider.callbacks.find(\n (value) => value.callbackId === request.callbackId,\n );\n\n if (!entry || !callback || request.profile.issuance !== \"active\") return yield* rejected();\n\n const result = yield* Effect.tryPromise({\n try: async (signal) => {\n const { configuration } = privateConfiguration(\n entry,\n fetch,\n timeoutSeconds,\n signal,\n \"grant\",\n );\n\n const state = client.randomState(),\n verifier = client.randomPKCECodeVerifier(),\n nonce = entry.provider.protocol === \"oidc\" ? client.randomNonce() : undefined;\n\n const challenge = await client.calculatePKCECodeChallenge(verifier);\n\n signal.throwIfAborted();\n const parameters = new URLSearchParams(entry.provider.authorizationParameters);\n\n for (const [key, value] of Object.entries({\n response_type: \"code\",\n response_mode: \"query\",\n redirect_uri: callback.redirectUri,\n scope: (\n compatibility?.authorizationScopes(\n request.profile.scopes,\n request.profile.retention === \"access-and-refresh\",\n ) ?? request.profile.scopes\n ).join(\" \"),\n state,\n code_challenge: challenge,\n code_challenge_method: \"S256\",\n }))\n parameters.set(key, value);\n if (nonce !== undefined) parameters.set(\"nonce\", nonce);\n if (entry.provider.protocol === \"oidc\" && entry.provider.maxAgeSeconds !== undefined)\n parameters.set(\"max_age\", String(entry.provider.maxAgeSeconds));\n appendResources(parameters, request.profile.resources);\n\n return {\n configuration: {\n provider: entry.provider.provider,\n protocol: entry.provider.protocol,\n configurationGeneration: entry.provider.configurationGeneration,\n issuer: entry.provider.issuer,\n responseIssuerMode: entry.provider.responseIssuerMode,\n callbackId: callback.callbackId,\n redirectUri: callback.redirectUri,\n profile: request.profile,\n },\n authorizationUrl: Redacted.make(\n client.buildAuthorizationUrl(configuration, parameters).href,\n ),\n secrets: {\n namespace: \"effect-auth/oauth-transaction-secrets/v1\" as const,\n state: Redacted.make(state),\n pkceVerifier: Redacted.make(verifier),\n ...(nonce === undefined ? {} : { oidcNonce: Redacted.make(nonce) }),\n },\n };\n },\n catch: unavailable,\n });\n\n return yield* snapshotOAuth(prepareOutput, result);\n });\n\n const exchangeGrant: OAuthConnectedProtocol[\"Service\"][\"exchangeGrant\"] = Effect.fn(\n \"OpenIdClientConnected.exchangeGrant\",\n )(function* (input) {\n const request = yield* snapshotOAuth(exchangeInput, input),\n saved = request.configuration;\n\n const entry = yield* retained(saved),\n provider = entry.provider;\n\n if (\n (provider.protocol === \"oidc\") !== (request.secrets.oidcNonce !== undefined) ||\n Redacted.value(request.response.state) !== Redacted.value(request.secrets.state) ||\n (provider.responseIssuerMode === \"required\"\n ? request.response.issuer !== provider.issuer\n : request.response.issuer !== undefined)\n )\n return yield* rejected();\n const start = yield* checkedStart(request.verificationStartedAt);\n\n const result = yield* Effect.tryPromise({\n try: async (signal) => {\n const invocation = privateConfiguration(\n entry,\n fetch,\n timeoutSeconds,\n signal,\n \"grant\",\n compatibility,\n {\n scopes: saved.profile.scopes,\n refreshRequired: saved.profile.retention === \"access-and-refresh\",\n operation: \"authorization_code\",\n },\n );\n\n const url = new URL(saved.redirectUri);\n\n url.searchParams.set(\"code\", Redacted.value(request.response.code));\n url.searchParams.set(\"state\", Redacted.value(request.response.state));\n if (request.response.issuer !== undefined)\n url.searchParams.set(\"iss\", request.response.issuer);\n const parameters = new URLSearchParams(provider.tokenParameters);\n\n appendResources(parameters, saved.profile.resources);\n\n const tokens = await client.authorizationCodeGrant(\n invocation.configuration,\n url,\n {\n expectedState: Redacted.value(request.secrets.state),\n pkceCodeVerifier: Redacted.value(request.secrets.pkceVerifier),\n ...(provider.protocol === \"oidc\"\n ? {\n idTokenExpected: true,\n expectedNonce: Redacted.value(request.secrets.oidcNonce!),\n ...(provider.maxAgeSeconds === undefined\n ? {}\n : { maxAge: provider.maxAgeSeconds }),\n }\n : {}),\n },\n parameters,\n );\n\n signal.throwIfAborted();\n if (tokens.token_type !== \"bearer\") throw unavailable();\n const metadata = invocation.metadata();\n let body: unknown;\n\n if (provider.protocol === \"oauth\") {\n const response = await client.fetchProtectedResource(\n invocation.configuration,\n tokens.access_token,\n new URL(provider.identitySource.url),\n \"GET\",\n undefined,\n new Headers(provider.identitySource.headers),\n );\n\n signal.throwIfAborted();\n if (\n response.status !== 200 ||\n response.headers.get(\"content-type\")?.split(\";\", 1)[0]?.trim().toLowerCase() !==\n \"application/json\"\n )\n throw unavailable();\n body = await response.json();\n signal.throwIfAborted();\n }\n\n return {\n tokens,\n metadata,\n body,\n };\n },\n catch: grantError,\n });\n\n const identity =\n provider.protocol === \"oidc\"\n ? yield* oidcIdentity(entry, result.tokens.claims(), request.secrets.oidcNonce!)\n : yield* decodeIdentity(entry, result.body);\n\n const refreshToken =\n saved.profile.retention === \"access-and-refresh\" ? result.tokens.refresh_token : undefined;\n\n const metadata = yield* tokenMetadata(\n saved.profile,\n result.metadata,\n start,\n refreshToken !== undefined,\n );\n\n return yield* snapshotOAuth(M.OAuthConnectedGrantResponse, {\n ...identity,\n ...metadata,\n material: {\n namespace: \"effect-auth/oauth-connected-token-material/v1\",\n accessToken: Redacted.make(result.tokens.access_token),\n ...(refreshToken === undefined ? {} : { refreshToken: Redacted.make(refreshToken) }),\n continuation: identity.continuation,\n },\n });\n });\n\n const refreshGrant: OAuthConnectedProtocol[\"Service\"][\"refreshGrant\"] = Effect.fn(\n \"OpenIdClientConnected.refreshGrant\",\n )(function* (input) {\n const request = yield* snapshotOAuth(refreshInput, input),\n saved = request.context.configuration;\n\n const entry = yield* retained(saved),\n provider = entry.provider,\n previous = request.material.continuation;\n\n if (\n saved.profile.retention !== \"access-and-refresh\" ||\n saved.profile.refresh === \"unsupported\" ||\n !request.material.refreshToken ||\n request.context.identity.provider !== provider.provider ||\n request.context.identity.issuer !== provider.issuer ||\n (provider.protocol === \"oidc\"\n ? previous._tag !== \"Oidc\" ||\n previous.clientId !== provider.clientId ||\n previous.nonce === undefined\n : previous._tag !== \"OAuth\") ||\n !sameStrings(request.context.metadata.scopes, saved.profile.scopes) ||\n !sameStrings(request.context.metadata.resources, saved.profile.resources)\n )\n return yield* unavailable();\n const start = yield* checkedStart(request.verificationStartedAt);\n\n if (\n (request.context.metadata.refreshUseUntilMillis !== undefined &&\n request.context.metadata.refreshUseUntilMillis <= start) ||\n (request.context.metadata.refreshExpiresAtMillis !== undefined &&\n request.context.metadata.refreshExpiresAtMillis <= start)\n )\n return yield* unavailable();\n\n const result = yield* Effect.tryPromise({\n try: async (signal) => {\n const invocation = privateConfiguration(\n entry,\n fetch,\n timeoutSeconds,\n signal,\n \"grant\",\n compatibility,\n {\n scopes: saved.profile.scopes,\n refreshRequired: true,\n operation: \"refresh_token\",\n },\n );\n\n const parameters = new URLSearchParams(provider.refreshParameters);\n\n if (compatibility?.includeRefreshScope !== false)\n parameters.set(\"scope\", saved.profile.scopes.join(\" \"));\n appendResources(parameters, saved.profile.resources);\n\n const tokens = await client.refreshTokenGrant(\n invocation.configuration,\n Redacted.value(request.material.refreshToken!),\n parameters,\n );\n\n signal.throwIfAborted();\n if (\n tokens.token_type !== \"bearer\" ||\n (saved.profile.refresh === \"rotating\" &&\n (!tokens.refresh_token ||\n tokens.refresh_token === Redacted.value(request.material.refreshToken!)))\n )\n throw unavailable();\n const metadata = invocation.metadata();\n let body: unknown;\n\n if (provider.protocol === \"oauth\") {\n const response = await client.fetchProtectedResource(\n invocation.configuration,\n tokens.access_token,\n new URL(provider.identitySource.url),\n \"GET\",\n undefined,\n new Headers(provider.identitySource.headers),\n );\n\n signal.throwIfAborted();\n if (\n response.status !== 200 ||\n response.headers.get(\"content-type\")?.split(\";\", 1)[0]?.trim().toLowerCase() !==\n \"application/json\"\n )\n throw unavailable();\n body = await response.json();\n signal.throwIfAborted();\n }\n\n return {\n tokens,\n metadata,\n body,\n };\n },\n catch: grantError,\n });\n\n if (provider.protocol === \"oidc\") {\n if (previous._tag !== \"Oidc\" || !previous.nonce) return yield* unavailable();\n if (result.tokens.id_token !== undefined)\n yield* oidcIdentity(entry, result.tokens.claims(), previous.nonce, {\n identity: request.context.identity,\n continuation: previous,\n });\n } else {\n const identity = yield* decodeIdentity(entry, result.body);\n\n if (identity.identity.subject !== request.context.identity.subject)\n return yield* unavailable();\n }\n const metadata = yield* tokenMetadata(saved.profile, result.metadata, start, true);\n const finishedAt = DateTime.toEpochMillis(yield* DateTime.now);\n\n if (\n (request.context.metadata.refreshUseUntilMillis !== undefined &&\n request.context.metadata.refreshUseUntilMillis <= finishedAt) ||\n (request.context.metadata.refreshExpiresAtMillis !== undefined &&\n request.context.metadata.refreshExpiresAtMillis <= finishedAt)\n )\n return yield* unavailable();\n\n return yield* snapshotOAuth(M.OAuthConnectedGrantResponse, {\n identity: request.context.identity,\n ...metadata,\n material: {\n namespace: \"effect-auth/oauth-connected-token-material/v1\",\n accessToken: Redacted.make(result.tokens.access_token),\n ...(result.tokens.refresh_token === undefined\n ? {}\n : { refreshToken: Redacted.make(result.tokens.refresh_token) }),\n continuation: previous,\n },\n });\n });\n\n const revokeGrant: OAuthConnectedProtocol[\"Service\"][\"revokeGrant\"] = Effect.fn(\n \"OpenIdClientConnected.revokeGrant\",\n )(function* (input) {\n const request = yield* snapshotOAuth(revokeInput, input),\n saved = request.context.configuration;\n\n const entry = yield* retained(saved),\n revocation = entry.provider.revocation;\n\n if (\n saved.profile.revocation !== \"cohort\" ||\n revocation.mode === \"unsupported\" ||\n (revocation.mode === \"provider-cohort\" && compatibility === undefined) ||\n (revocation.mode === \"rfc7009\" &&\n request.material.refreshToken !== undefined &&\n revocation.tokenTypes !== \"access-and-refresh\") ||\n request.context.identity.provider !== entry.provider.provider ||\n request.context.identity.issuer !== entry.provider.issuer ||\n (entry.provider.protocol === \"oidc\"\n ? request.material.continuation._tag !== \"Oidc\" ||\n request.material.continuation.clientId !== entry.provider.clientId\n : request.material.continuation._tag !== \"OAuth\")\n )\n return yield* unavailable();\n if (revocation.mode === \"provider-cohort\") {\n yield* providerRevocation.revoke({\n clientId: entry.provider.clientId,\n authentication: entry.provider.authentication,\n context: request.context,\n material: request.material,\n });\n\n return \"Confirmed\" as const;\n }\n yield* Effect.tryPromise({\n try: async (signal) => {\n const { configuration } = privateConfiguration(\n entry,\n fetch,\n timeoutSeconds,\n signal,\n \"revoke\",\n );\n\n if (request.material.refreshToken !== undefined) {\n await client.tokenRevocation(\n configuration,\n Redacted.value(request.material.refreshToken),\n { token_type_hint: \"refresh_token\" },\n );\n signal.throwIfAborted();\n }\n await client.tokenRevocation(configuration, Redacted.value(request.material.accessToken), {\n token_type_hint: \"access_token\",\n });\n signal.throwIfAborted();\n },\n catch: unavailable,\n });\n\n return \"Confirmed\" as const;\n });\n\n return OAuthConnectedProtocol.of({\n prepareAuthorization: (input) => safe(prepareAuthorization(input)),\n exchangeGrant: (input) => safe(exchangeGrant(input)),\n refreshGrant: (input) => safe(refreshGrant(input)),\n revokeGrant: (input) => safe(revokeGrant(input)),\n });\n}, safe);\n\nexport const makeOpenIdClientConnectedProtocol = <R = never>(\n options: OpenIdClientConnectedProtocolOptions<R>,\n): Effect.Effect<\n OAuthConnectedProtocol[\"Service\"],\n OpenIdClientConfigurationError | OAuthUnavailable,\n R\n> =>\n makeConnectedProtocolWithCompatibility(options).pipe(\n Effect.provide(ProviderRevocation.layerUnsupported),\n );\n\nexport const openIdClientConnectedProtocolLayer = <R = never>(\n options: OpenIdClientConnectedProtocolOptions<R>,\n) => Layer.effect(OAuthConnectedProtocol, makeOpenIdClientConnectedProtocol(options));\n"],"mappings":";;;;;;;;;;;;;;;;AAmCA,MAAM,oBAAoB,iBAAiB,KAAK,CAAC,CAAC;AAClD,MAAM,iBAAiB,sBAAsB,KAAK,CAAC,CAAC;AAEpD,MAAM,QAAiB,WACrB,OAAO,KACL,OAAO,UAAU,UACf,MAAM,QAAQ,KAAK,IAAI,kBAAkB,kBAAkB,KAAK,IAAI,OAAO,IAC7E,GACA,OAAO,YAAY,UAAsD;CACvE,IAAI,MAAM,cAAc,KAAK,GAAG,OAAO,OAAO;CAE9C,OAAO,MAAM,QAAQ,KAAK,IAAI,OAAO,KAAK,YAAY,CAAC,IAAI,OAAO,UAAU,KAAK;AACnF,CAAC,CACH;;AAGF,MAAM,cAAc,UAClB,iBAAiB,0BAChB,iBAAiB,OAAO,eAAe,MAAM,iBAAiB,0BAC9D,iBAAiB,OAAO,qBACvB,MAAM,WAAW,OACjB,MAAM,UAAU,kBACd,SAAS,IACT,YAAY;AAElB,MAAM,eAAe,OAAO,OAAO;CACjC,SAASA;CACT,YAAY;CACZ,QAAQ;AACV,CAAC;AAED,MAAM,gBAAgB,OAAO,OAAO;CAClC,GAAG,yBAAyB;CAC5B,eAAeC;AACjB,CAAC;AAED,MAAM,gBAAgB,OAAO,OAC3B,OAAO,OAAO;CACZ,eAAeA;CACf,SA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Ae,UAAU,KAAK,aAAa,KAAK,CAAC;EACjD,cAAc,UAAU,KAAK,YAAY,KAAK,CAAC;CACjD,CAAC;AACH,GAAG,IAAI;AAEP,MAAa,qCACX,YAMA,uCAAuC,OAAO,CAAC,CAAC,KAC9C,OAAO,QAAQ,mBAAmB,gBAAgB,CACpD;AAEF,MAAa,sCACX,YACG,MAAM,OAAO,wBAAwB,kCAAkC,OAAO,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import "../signInErrors.mjs";
|
|
2
|
+
import { Effect, Schema } from "effect";
|
|
3
|
+
//#region src/oauth/openid-client/profile.d.ts
|
|
4
|
+
/** Standard OpenID Connect user claims returned in a verified ID token. This
|
|
5
|
+
* does not request additional scopes or fetch UserInfo. Protocol claims and
|
|
6
|
+
* credentials are excluded; values such as email_verified describe the provider's
|
|
7
|
+
* assertion and never authorize local account linking by themselves. */
|
|
8
|
+
declare const OidcUserProfile: Schema.Struct<{
|
|
9
|
+
readonly name: Schema.optionalKey<Schema.String>;
|
|
10
|
+
readonly given_name: Schema.optionalKey<Schema.String>;
|
|
11
|
+
readonly family_name: Schema.optionalKey<Schema.String>;
|
|
12
|
+
readonly middle_name: Schema.optionalKey<Schema.String>;
|
|
13
|
+
readonly nickname: Schema.optionalKey<Schema.String>;
|
|
14
|
+
readonly preferred_username: Schema.optionalKey<Schema.String>;
|
|
15
|
+
readonly profile: Schema.optionalKey<Schema.String>;
|
|
16
|
+
readonly picture: Schema.optionalKey<Schema.String>;
|
|
17
|
+
readonly website: Schema.optionalKey<Schema.String>;
|
|
18
|
+
readonly email: Schema.optionalKey<Schema.String>;
|
|
19
|
+
readonly email_verified: Schema.optionalKey<Schema.Boolean>;
|
|
20
|
+
readonly gender: Schema.optionalKey<Schema.String>;
|
|
21
|
+
readonly birthdate: Schema.optionalKey<Schema.String>;
|
|
22
|
+
readonly zoneinfo: Schema.optionalKey<Schema.String>;
|
|
23
|
+
readonly locale: Schema.optionalKey<Schema.String>;
|
|
24
|
+
readonly phone_number: Schema.optionalKey<Schema.String>;
|
|
25
|
+
readonly phone_number_verified: Schema.optionalKey<Schema.Boolean>;
|
|
26
|
+
readonly address: Schema.optionalKey<Schema.Struct<{
|
|
27
|
+
readonly formatted: Schema.optionalKey<Schema.String>;
|
|
28
|
+
readonly street_address: Schema.optionalKey<Schema.String>;
|
|
29
|
+
readonly locality: Schema.optionalKey<Schema.String>;
|
|
30
|
+
readonly region: Schema.optionalKey<Schema.String>;
|
|
31
|
+
readonly postal_code: Schema.optionalKey<Schema.String>;
|
|
32
|
+
readonly country: Schema.optionalKey<Schema.String>;
|
|
33
|
+
}>>;
|
|
34
|
+
readonly updated_at: Schema.optionalKey<Schema.Int>;
|
|
35
|
+
}>;
|
|
36
|
+
type OidcUserProfile = typeof OidcUserProfile.Type;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { OidcUserProfile };
|
|
39
|
+
//# sourceMappingURL=profile.d.mts.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { OAuthProtocolRejected } from "../signInErrors.mjs";
|
|
2
|
+
import { Effect, Schema } from "effect";
|
|
3
|
+
//#region src/oauth/openid-client/profile.ts
|
|
4
|
+
const text = Schema.String.check(Schema.isMaxLength(256));
|
|
5
|
+
const url = Schema.String.check(Schema.isMaxLength(2048));
|
|
6
|
+
/** Standard OpenID Connect user claims returned in a verified ID token. This
|
|
7
|
+
* does not request additional scopes or fetch UserInfo. Protocol claims and
|
|
8
|
+
* credentials are excluded; values such as email_verified describe the provider's
|
|
9
|
+
* assertion and never authorize local account linking by themselves. */
|
|
10
|
+
const OidcUserProfile = Schema.Struct({
|
|
11
|
+
name: Schema.optionalKey(text),
|
|
12
|
+
given_name: Schema.optionalKey(text),
|
|
13
|
+
family_name: Schema.optionalKey(text),
|
|
14
|
+
middle_name: Schema.optionalKey(text),
|
|
15
|
+
nickname: Schema.optionalKey(text),
|
|
16
|
+
preferred_username: Schema.optionalKey(text),
|
|
17
|
+
profile: Schema.optionalKey(url),
|
|
18
|
+
picture: Schema.optionalKey(url),
|
|
19
|
+
website: Schema.optionalKey(url),
|
|
20
|
+
email: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(320))),
|
|
21
|
+
email_verified: Schema.optionalKey(Schema.Boolean),
|
|
22
|
+
gender: Schema.optionalKey(text),
|
|
23
|
+
birthdate: Schema.optionalKey(text),
|
|
24
|
+
zoneinfo: Schema.optionalKey(text),
|
|
25
|
+
locale: Schema.optionalKey(text),
|
|
26
|
+
phone_number: Schema.optionalKey(text),
|
|
27
|
+
phone_number_verified: Schema.optionalKey(Schema.Boolean),
|
|
28
|
+
address: Schema.optionalKey(Schema.Struct({
|
|
29
|
+
formatted: Schema.optionalKey(url),
|
|
30
|
+
street_address: Schema.optionalKey(url),
|
|
31
|
+
locality: Schema.optionalKey(text),
|
|
32
|
+
region: Schema.optionalKey(text),
|
|
33
|
+
postal_code: Schema.optionalKey(text),
|
|
34
|
+
country: Schema.optionalKey(text)
|
|
35
|
+
})),
|
|
36
|
+
updated_at: Schema.optionalKey(Schema.Int.check(Schema.isBetween({
|
|
37
|
+
minimum: 0,
|
|
38
|
+
maximum: Number.MAX_SAFE_INTEGER
|
|
39
|
+
})))
|
|
40
|
+
});
|
|
41
|
+
const decodeOidcProfile = Effect.fn("OpenIdClient.decodeProfile")(function* (claims) {
|
|
42
|
+
const profile = yield* Schema.decodeUnknownEffect(OidcUserProfile)(claims).pipe(Effect.mapError(() => OAuthProtocolRejected.make({})));
|
|
43
|
+
if (Object.keys(profile).length === 0) return void 0;
|
|
44
|
+
const displayName = profile.name?.trim() || profile.preferred_username;
|
|
45
|
+
return {
|
|
46
|
+
...displayName === void 0 ? {} : { displayName },
|
|
47
|
+
...profile.preferred_username === void 0 ? {} : { handle: profile.preferred_username },
|
|
48
|
+
...profile.picture === void 0 ? {} : { avatarUrl: profile.picture },
|
|
49
|
+
...profile.profile === void 0 ? {} : { profileUrl: profile.profile },
|
|
50
|
+
...profile.email === void 0 ? {} : { email: profile.email },
|
|
51
|
+
...profile.email_verified === void 0 ? {} : { emailVerified: profile.email_verified },
|
|
52
|
+
providerData: profile
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
//#endregion
|
|
56
|
+
export { OidcUserProfile, decodeOidcProfile };
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=profile.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile.mjs","names":[],"sources":["../../../src/oauth/openid-client/profile.ts"],"sourcesContent":["import { Effect, Schema } from \"effect\";\n\nimport { OAuthProtocolRejected } from \"../signInErrors\";\nimport type { OAuthDisplayProfile } from \"../signInModels\";\n\nconst text = Schema.String.check(Schema.isMaxLength(256));\nconst url = Schema.String.check(Schema.isMaxLength(2048));\n\n/** Standard OpenID Connect user claims returned in a verified ID token. This\n * does not request additional scopes or fetch UserInfo. Protocol claims and\n * credentials are excluded; values such as email_verified describe the provider's\n * assertion and never authorize local account linking by themselves. */\nexport const OidcUserProfile = Schema.Struct({\n name: Schema.optionalKey(text),\n given_name: Schema.optionalKey(text),\n family_name: Schema.optionalKey(text),\n middle_name: Schema.optionalKey(text),\n nickname: Schema.optionalKey(text),\n preferred_username: Schema.optionalKey(text),\n profile: Schema.optionalKey(url),\n picture: Schema.optionalKey(url),\n website: Schema.optionalKey(url),\n email: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(320))),\n email_verified: Schema.optionalKey(Schema.Boolean),\n gender: Schema.optionalKey(text),\n birthdate: Schema.optionalKey(text),\n zoneinfo: Schema.optionalKey(text),\n locale: Schema.optionalKey(text),\n phone_number: Schema.optionalKey(text),\n phone_number_verified: Schema.optionalKey(Schema.Boolean),\n address: Schema.optionalKey(\n Schema.Struct({\n formatted: Schema.optionalKey(url),\n street_address: Schema.optionalKey(url),\n locality: Schema.optionalKey(text),\n region: Schema.optionalKey(text),\n postal_code: Schema.optionalKey(text),\n country: Schema.optionalKey(text),\n }),\n ),\n updated_at: Schema.optionalKey(\n Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER })),\n ),\n});\n\nexport type OidcUserProfile = typeof OidcUserProfile.Type;\n\nexport const decodeOidcProfile = Effect.fn(\"OpenIdClient.decodeProfile\")(function* (\n claims: unknown,\n): Effect.fn.Return<OAuthDisplayProfile | undefined, OAuthProtocolRejected> {\n // oxlint-disable-next-line no-restricted-properties -- Select standard user claims from an already verified ID token.\n const profile = yield* Schema.decodeUnknownEffect(OidcUserProfile)(claims).pipe(\n Effect.mapError(() => OAuthProtocolRejected.make({})),\n );\n\n if (Object.keys(profile).length === 0) return undefined;\n const displayName = profile.name?.trim() || profile.preferred_username;\n\n return {\n ...(displayName === undefined ? {} : { displayName }),\n ...(profile.preferred_username === undefined ? {} : { handle: profile.preferred_username }),\n ...(profile.picture === undefined ? {} : { avatarUrl: profile.picture }),\n ...(profile.profile === undefined ? {} : { profileUrl: profile.profile }),\n ...(profile.email === undefined ? {} : { email: profile.email }),\n ...(profile.email_verified === undefined ? {} : { emailVerified: profile.email_verified }),\n providerData: profile,\n };\n});\n"],"mappings":";;;AAKA,MAAM,OAAO,OAAO,OAAO,MAAM,OAAO,YAAY,GAAG,CAAC;AACxD,MAAM,MAAM,OAAO,OAAO,MAAM,OAAO,YAAY,IAAI,CAAC;;;;;AAMxD,MAAa,kBAAkB,OAAO,OAAO;CAC3C,MAAM,OAAO,YAAY,IAAI;CAC7B,YAAY,OAAO,YAAY,IAAI;CACnC,aAAa,OAAO,YAAY,IAAI;CACpC,aAAa,OAAO,YAAY,IAAI;CACpC,UAAU,OAAO,YAAY,IAAI;CACjC,oBAAoB,OAAO,YAAY,IAAI;CAC3C,SAAS,OAAO,YAAY,GAAG;CAC/B,SAAS,OAAO,YAAY,GAAG;CAC/B,SAAS,OAAO,YAAY,GAAG;CAC/B,OAAO,OAAO,YAAY,OAAO,OAAO,MAAM,OAAO,YAAY,GAAG,CAAC,CAAC;CACtE,gBAAgB,OAAO,YAAY,OAAO,OAAO;CACjD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AM;EAC9D,GAAI,QAAQ,mBAAmB,KAAA,IAAY,CAAC,IAAI,EAAE,eAAe,QAAQ,eAAe;EACxF,cAAc;CAChB;AACF,CAAC"}
|
|
@@ -8,6 +8,7 @@ import { OAuthProtocol } from "../OAuthProtocol.mjs";
|
|
|
8
8
|
import { DefiniteTokenRejection, tokenCompatibility } from "./compatibility.mjs";
|
|
9
9
|
import { boundedFetch } from "./transport.mjs";
|
|
10
10
|
import { clientAuthentication, installConfigurations, makeAuthorizationParameters } from "./configuration.mjs";
|
|
11
|
+
import { decodeOidcProfile } from "./profile.mjs";
|
|
11
12
|
import { Cause, DateTime, Effect, Layer, Redacted, Schema } from "effect";
|
|
12
13
|
import * as client from "openid-client";
|
|
13
14
|
//#region src/oauth/openid-client/protocol.ts
|
|
@@ -181,12 +182,14 @@ const makeOpenIdClientOAuthProtocol = Effect.fn("makeOpenIdClientOAuthProtocol")
|
|
|
181
182
|
const now = DateTime.toEpochMillis(yield* DateTime.now) / 1e3;
|
|
182
183
|
const audience = typeof claims.aud === "string" ? claims.aud : claims.aud[0];
|
|
183
184
|
if (provider.protocol !== "oidc" || claims.iss !== provider.issuer || audience !== provider.clientId || claims.azp !== void 0 && claims.azp !== provider.clientId || claims.exp <= now || claims.iat > now || claims.nbf !== void 0 && claims.nbf > now || claims.auth_time !== void 0 && claims.auth_time > now || provider.maxAgeSeconds !== void 0 && (claims.auth_time === void 0 || claims.auth_time + provider.maxAgeSeconds < Math.floor(now))) return yield* rejected();
|
|
185
|
+
const profile = yield* decodeOidcProfile(exchanged.claims);
|
|
184
186
|
return yield* snapshotOAuth(OAuthVerifiedExternalIdentity, {
|
|
185
187
|
identity: {
|
|
186
188
|
provider: provider.provider,
|
|
187
189
|
issuer: provider.issuer,
|
|
188
190
|
subject: claims.sub
|
|
189
191
|
},
|
|
192
|
+
...profile === void 0 ? {} : { profile },
|
|
190
193
|
...claims.auth_time === void 0 ? {} : { upstreamAuthenticatedAt: DateTime.makeUnsafe(Math.min(startedAt, claims.auth_time * 1e3)) }
|
|
191
194
|
});
|
|
192
195
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.mjs","names":[],"sources":["../../../src/oauth/openid-client/protocol.ts"],"sourcesContent":["import { Cause, DateTime, Effect, Layer, Redacted, Schema } from \"effect\";\nimport * as client from \"openid-client\";\n\nimport { reportAuthFailure } from \"../../internal/diagnostics\";\nimport { RequestBindingFlowId } from \"../../operations/requestBinding\";\nimport { OAuthProtocol } from \"../OAuthProtocol\";\nimport { OAuthProviderKey } from \"../schema\";\nimport { OAuthProtocolRejected, OAuthRejected, OAuthUnavailable } from \"../signInErrors\";\nimport {\n OAuthCallbackId,\n OAuthCodeResponse,\n OAuthDisplayProfile,\n OAuthProtocolConfiguration,\n OAuthProtocolPreparation,\n OAuthTransactionSecrets,\n OAuthVerifiedExternalIdentity,\n} from \"../signInModels\";\nimport { snapshotOAuth } from \"../signInSnapshot\";\nimport { DefiniteTokenRejection, tokenCompatibility } from \"./compatibility\";\nimport {\n clientAuthentication,\n installConfigurations,\n makeAuthorizationParameters,\n type InstalledProvider,\n} from \"./configuration\";\nimport {\n type OpenIdClientConfigurationError,\n type OpenIdClientOAuthProtocolOptions,\n} from \"./models\";\nimport { boundedFetch } from \"./transport\";\n\nconst beginInput = Schema.Struct({\n provider: OAuthProviderKey,\n callbackId: OAuthCallbackId,\n flowId: RequestBindingFlowId,\n});\n\nconst exchangeInput = Schema.toType(\n Schema.Struct({\n configuration: OAuthProtocolConfiguration,\n response: OAuthCodeResponse,\n secrets: OAuthTransactionSecrets,\n verificationStartedAt: Schema.DateTimeUtcFromMillis,\n }),\n);\n\nconst numericDate = Schema.Finite.check(Schema.isBetween({ minimum: 0, maximum: 8640000000000 }));\n\nconst claimsSchema = Schema.Struct({\n iss: Schema.String,\n sub: OAuthVerifiedExternalIdentity.fields.identity.fields.subject,\n aud: Schema.Union([\n Schema.String,\n Schema.Array(Schema.String).check(Schema.isMinLength(1), Schema.isMaxLength(1)),\n ]),\n azp: Schema.optionalKey(Schema.String),\n exp: numericDate,\n iat: numericDate,\n nbf: Schema.optionalKey(numericDate),\n auth_time: Schema.optionalKey(numericDate),\n});\n\nconst plainIdentitySchema = Schema.Struct({\n subject: OAuthVerifiedExternalIdentity.fields.identity.fields.subject,\n profile: Schema.optionalKey(OAuthDisplayProfile),\n});\n\nconst unavailable = () => OAuthUnavailable.make({});\nconst rejected = () => OAuthProtocolRejected.make({});\n\nconst unavailableOnDefect = <A, E, R>(effect: Effect.Effect<A, E, R>) =>\n effect.pipe(\n Effect.tapCause((cause) =>\n Cause.hasDies(cause) ? reportAuthFailure(\"oauth-protocol\", cause) : Effect.void,\n ),\n Effect.catchCause((cause): Effect.Effect<never, E | OAuthUnavailable> => {\n if (Cause.hasInterrupts(cause)) return Effect.interrupt;\n if (Cause.hasDies(cause)) return Effect.fail(unavailable());\n\n return Effect.failCause(cause);\n }),\n );\n\n/** Only precise claim errors and a fully parsed invalid_grant are definite.\n * INVALID_RESPONSE also covers signature/key/transport faults; keep it ambiguous. */\nconst grantError = (error: unknown) => {\n if (\n error instanceof DefiniteTokenRejection ||\n (error instanceof client.ClientError && error.cause instanceof DefiniteTokenRejection)\n )\n return rejected();\n if (\n error instanceof client.ClientError &&\n (error.code === \"OAUTH_JWT_CLAIM_COMPARISON_FAILED\" ||\n error.code === \"OAUTH_JWT_TIMESTAMP_CHECK_FAILED\")\n )\n return rejected();\n if (\n error instanceof client.ResponseBodyError &&\n error.status === 400 &&\n error.error === \"invalid_grant\"\n )\n return rejected();\n\n return unavailable();\n};\n\nconst privateConfiguration = <R>(\n entry: InstalledProvider<R>,\n timeout: number,\n fetch: client.CustomFetch,\n signal: AbortSignal,\n) => {\n const provider = entry.provider;\n const compatibility = provider.protocol === \"oauth\" ? provider[tokenCompatibility] : undefined;\n\n const configuration = new client.Configuration(\n entry.metadata,\n provider.clientId,\n {\n [client.clockSkew]: 0,\n [client.clockTolerance]: 0,\n ...(provider.protocol === \"oidc\"\n ? { id_token_signed_response_alg: provider.idTokenSignedResponseAlg }\n : {}),\n },\n clientAuthentication(provider.authentication),\n );\n\n configuration.timeout = timeout;\n const transport = boundedFetch(fetch, signal, entry.allowedUrls);\n\n configuration[client.customFetch] =\n compatibility === undefined\n ? transport\n : async (url, options) => {\n const response = await transport(url, options);\n\n if (url === new URL(entry.metadata.token_endpoint!).href) {\n const body: unknown = await response.clone().json();\n\n signal.throwIfAborted();\n compatibility.inspectReceipt(\n { body, status: response.status, contentType: response.headers.get(\"content-type\") },\n {\n scopes: provider.scopes,\n refreshRequired: false,\n operation: \"authorization_code\",\n },\n );\n signal.throwIfAborted();\n }\n\n return response;\n };\n if (provider.protocol === \"oidc\") client.enableNonRepudiationChecks(configuration);\n\n return configuration;\n};\n\nexport const makeOpenIdClientOAuthProtocol = Effect.fn(\"makeOpenIdClientOAuthProtocol\")(\n // Capture one provider table; each generation retains its own receipt rules.\n function* <R = never>(\n options: OpenIdClientOAuthProtocolOptions<R>,\n ): Effect.fn.Return<\n OAuthProtocol[\"Service\"],\n OpenIdClientConfigurationError | OAuthUnavailable,\n R\n > {\n const context = yield* Effect.context<R>();\n const { installed, fetch, timeoutSeconds } = yield* installConfigurations(options);\n\n const prepareAuthorization: OAuthProtocol[\"Service\"][\"prepareAuthorization\"] = Effect.fn(\n \"OpenIdClient.prepareAuthorization\",\n )(function* (input) {\n const request = yield* Schema.decodeEffect(beginInput)(input).pipe(\n Effect.mapError(() => OAuthRejected.make({})),\n );\n\n const entry = installed.find(\n ({ provider }) => provider.issuance === \"active\" && provider.provider === request.provider,\n );\n\n const provider = entry?.provider;\n\n const callback = provider?.callbacks.find(\n (candidate) => candidate.callbackId === request.callbackId,\n );\n\n if (entry === undefined || provider === undefined || callback === undefined)\n return yield* OAuthRejected.make({});\n\n const result = yield* Effect.tryPromise({\n try: async (signal) => {\n const configuration = privateConfiguration(entry, timeoutSeconds, fetch, signal);\n\n const state = client.randomState();\n const verifier = client.randomPKCECodeVerifier();\n const nonce = provider.protocol === \"oidc\" ? client.randomNonce() : undefined;\n const challenge = await client.calculatePKCECodeChallenge(verifier);\n\n signal.throwIfAborted();\n\n const url = client.buildAuthorizationUrl(\n configuration,\n makeAuthorizationParameters(provider, callback.redirectUri, {\n state,\n challenge,\n ...(nonce === undefined ? {} : { nonce }),\n }),\n );\n\n return {\n configuration: {\n provider: provider.provider,\n protocol: provider.protocol,\n configurationGeneration: provider.configurationGeneration,\n issuer: provider.issuer,\n responseIssuerMode: provider.responseIssuerMode,\n callbackId: callback.callbackId,\n redirectUri: callback.redirectUri,\n },\n authorizationUrl: Redacted.make(url.href),\n secrets: {\n namespace: \"effect-auth/oauth-transaction-secrets/v1\" as const,\n state: Redacted.make(state),\n pkceVerifier: Redacted.make(verifier),\n ...(nonce === undefined ? {} : { oidcNonce: Redacted.make(nonce) }),\n },\n };\n },\n catch: unavailable,\n });\n\n return yield* snapshotOAuth(OAuthProtocolPreparation, result);\n });\n\n const exchangeVerifiedIdentity: OAuthProtocol[\"Service\"][\"exchangeVerifiedIdentity\"] =\n Effect.fn(\"OpenIdClient.exchangeVerifiedIdentity\")(function* (input) {\n const request = yield* snapshotOAuth(exchangeInput, input);\n const saved = request.configuration;\n\n const entry = installed.find(\n ({ provider }) =>\n provider.provider === saved.provider &&\n provider.configurationGeneration === saved.configurationGeneration,\n );\n\n if (entry === undefined) return yield* unavailable();\n const provider = entry.provider;\n\n const callback = provider.callbacks.find(\n (candidate) => candidate.callbackId === saved.callbackId,\n );\n\n if (\n provider.protocol !== saved.protocol ||\n provider.issuer !== saved.issuer ||\n provider.responseIssuerMode !== saved.responseIssuerMode ||\n callback?.redirectUri !== saved.redirectUri\n )\n return yield* unavailable();\n if (\n (provider.protocol === \"oidc\") !== (request.secrets.oidcNonce !== undefined) ||\n Redacted.value(request.response.state) !== Redacted.value(request.secrets.state) ||\n (provider.responseIssuerMode === \"required\"\n ? request.response.issuer !== provider.issuer\n : request.response.issuer !== undefined)\n )\n return yield* rejected();\n const startedAt = DateTime.toEpochMillis(request.verificationStartedAt);\n\n if (startedAt < 0 || startedAt > DateTime.toEpochMillis(yield* DateTime.now))\n return yield* rejected();\n\n const exchanged = yield* Effect.tryPromise({\n try: async (signal) => {\n const configuration = privateConfiguration(entry, timeoutSeconds, fetch, signal);\n\n const currentUrl = new URL(saved.redirectUri);\n\n currentUrl.searchParams.set(\"code\", Redacted.value(request.response.code));\n currentUrl.searchParams.set(\"state\", Redacted.value(request.response.state));\n if (request.response.issuer !== undefined)\n currentUrl.searchParams.set(\"iss\", request.response.issuer);\n\n const tokens = await client.authorizationCodeGrant(\n configuration,\n currentUrl,\n {\n pkceCodeVerifier: Redacted.value(request.secrets.pkceVerifier),\n expectedState: Redacted.value(request.secrets.state),\n ...(provider.protocol === \"oidc\"\n ? {\n expectedNonce: Redacted.value(request.secrets.oidcNonce!),\n idTokenExpected: true,\n ...(provider.maxAgeSeconds === undefined\n ? {}\n : { maxAge: provider.maxAgeSeconds }),\n }\n : {}),\n },\n provider.tokenParameters,\n );\n\n signal.throwIfAborted();\n if (provider.protocol === \"oidc\")\n return { protocol: \"oidc\" as const, claims: tokens.claims() };\n if (tokens.token_type !== \"bearer\") throw unavailable();\n\n const response = await client.fetchProtectedResource(\n configuration,\n tokens.access_token,\n new URL(provider.identitySource.url),\n \"GET\",\n undefined,\n new Headers(provider.identitySource.headers),\n );\n\n signal.throwIfAborted();\n if (\n response.status !== 200 ||\n response.headers.get(\"content-type\")?.split(\";\", 1)[0]?.trim().toLowerCase() !==\n \"application/json\"\n )\n throw unavailable();\n const body: unknown = await response.json();\n\n signal.throwIfAborted();\n\n return { protocol: \"oauth\" as const, body };\n },\n catch: grantError,\n });\n\n if (exchanged.protocol === \"oidc\") {\n // oxlint-disable-next-line no-restricted-properties -- Project validated foreign ID-token claims into the adapter's stricter bounded profile.\n const claims = yield* Schema.decodeUnknownEffect(claimsSchema)(exchanged.claims).pipe(\n Effect.mapError(rejected),\n );\n\n const now = DateTime.toEpochMillis(yield* DateTime.now) / 1000;\n const audience = typeof claims.aud === \"string\" ? claims.aud : claims.aud[0];\n\n if (\n provider.protocol !== \"oidc\" ||\n claims.iss !== provider.issuer ||\n audience !== provider.clientId ||\n (claims.azp !== undefined && claims.azp !== provider.clientId) ||\n claims.exp <= now ||\n claims.iat > now ||\n (claims.nbf !== undefined && claims.nbf > now) ||\n (claims.auth_time !== undefined && claims.auth_time > now) ||\n (provider.maxAgeSeconds !== undefined &&\n (claims.auth_time === undefined ||\n claims.auth_time + provider.maxAgeSeconds < Math.floor(now)))\n )\n return yield* rejected();\n\n return yield* snapshotOAuth(OAuthVerifiedExternalIdentity, {\n identity: { provider: provider.provider, issuer: provider.issuer, subject: claims.sub },\n ...(claims.auth_time === undefined\n ? {}\n : {\n upstreamAuthenticatedAt: DateTime.makeUnsafe(\n Math.min(startedAt, claims.auth_time * 1000),\n ),\n }),\n });\n }\n if (provider.protocol !== \"oauth\") return yield* unavailable();\n\n const decoded = yield* Effect.suspend(() =>\n provider.identitySource.decodeIdentity(exchanged.body),\n ).pipe(\n Effect.provideContext(context),\n Effect.catchCause(\n (cause): Effect.Effect<never, OAuthProtocolRejected | OAuthUnavailable> => {\n if (Cause.hasInterrupts(cause))\n return reportAuthFailure(\"oauth-identity\", cause).pipe(\n Effect.andThen(Effect.interrupt),\n );\n if (\n cause.reasons.length === 1 &&\n cause.reasons[0]?._tag === \"Fail\" &&\n Schema.is(OAuthProtocolRejected)(cause.reasons[0].error)\n )\n return Effect.fail(rejected());\n\n return reportAuthFailure(\"oauth-identity\", cause).pipe(\n Effect.andThen(Effect.fail(unavailable())),\n );\n },\n ),\n );\n\n const identity = yield* Schema.decodeEffect(plainIdentitySchema)(decoded).pipe(\n Effect.mapError(rejected),\n );\n\n return yield* snapshotOAuth(OAuthVerifiedExternalIdentity, {\n identity: {\n provider: provider.provider,\n issuer: provider.issuer,\n subject: identity.subject,\n },\n ...(identity.profile === undefined ? {} : { profile: identity.profile }),\n });\n });\n\n return OAuthProtocol.of({\n prepareAuthorization: (input) => unavailableOnDefect(prepareAuthorization(input)),\n exchangeVerifiedIdentity: (input) => unavailableOnDefect(exchangeVerifiedIdentity(input)),\n });\n },\n unavailableOnDefect,\n);\n\nexport const openIdClientOAuthProtocolLayer = <R = never>(\n options: OpenIdClientOAuthProtocolOptions<R>,\n) => Layer.effect(OAuthProtocol, makeOpenIdClientOAuthProtocol(options));\n"],"mappings":";;;;;;;;;;;;;AA+BA,MAAM,aAAa,OAAO,OAAO;CAC/B,UAAU;CACV,YAAY;CACZ,QAAQ;AACV,CAAC;AAED,MAAM,gBAAgB,OAAO,OAC3B,OAAO,OAAO;CACZ,eAAe;CACf,UAAU;CACV,SAAS;CACT,uBAAuB,OAAO;AAChC,CAAC,CACH;AAEA,MAAM,cAAc,OAAO,OAAO,MAAM,OAAO,UAAU;CAAE,SAAS;CAAG,SAAS;AAAc,CAAC,CAAC;AAEhG,MAAM,eAAe,OAAO,OAAO;CACjC,KAAK,OAAO;CACZ,KAAK,8BAA8B,OAAO,SAAS,OAAO;CAC1D,KAAK,OAAO,MAAM,CAChB,OAAO,QACP,OAAO,MAAM,OAAO,MAAM,CAAC,CAAC,MAAM,OAAO,YAAY,CAAC,GAAG,OAAO,YAAY,CAAC,CAAC,CAChF,CAAC;CACD,KAAK,OAAO,YAAY,OAAO,MAAM;CACrC,KAAK;CACL,KAAK;CACL,KAAK,OAAO,YAAY,WAAW;CACnC,WAAW,OAAO,YAAY,WAAW;AAC3C,CAAC;AAED,MAAM,sBAAsB,OAAO,OAAO;CACxC,SAAS,8BAA8B,OAAO,SAAS,OAAO;CAC9D,SAAS,OAAO,YAAY,mBAAmB;AACjD,CAAC;AAED,MAAM,oBAAoB,iBAAiB,KAAK,CAAC,CAAC;AAClD,MAAM,iBAAiB,sBAAsB,KAAK,CAAC,CAAC;AAEpD,MAAM,uBAAgC,WACpC,OAAO,KACL,OAAO,UAAU,UACf,MAAM,QAAQ,KAAK,IAAI,kBAAkB,kBAAkB,KAAK,IAAI,OA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GAC7B,OAAO,YACJ,UAA0E;GACzE,IAAI,MAAM,cAAc,KAAK,GAC3B,OAAO,kBAAkB,kBAAkB,KAAK,CAAC,CAAC,KAChD,OAAO,QAAQ,OAAO,SAAS,CACjC;GACF,IACE,MAAM,QAAQ,WAAW,KACzB,MAAM,QAAQ,EAAE,EAAE,SAAS,UAC3B,OAAO,GAAG,qBAAqB,CAAC,CAAC,MAAM,QAAQ,EAAE,CAAC,KAAK,GAEvD,OAAO,OAAO,KAAK,SAAS,CAAC;GAE/B,OAAO,kBAAkB,kBAAkB,KAAK,CAAC,CAAC,KAChD,OAAO,QAAQ,OAAO,KAAK,YAAY,CAAC,CAAC,CAC3C;EACF,CACF,CACF;EAEA,MAAM,WAAW,OAAO,OAAO,aAAa,mBAAmB,CAAC,CAAC,OAAO,CAAC,CAAC,KACxE,OAAO,SAAS,QAAQ,CAC1B;EAEA,OAAO,OAAO,cAAc,+BAA+B;GACzD,UAAU;IACR,UAAU,SAAS;IACnB,QAAQ,SAAS;IACjB,SAAS,SAAS;GACpB;GACA,GAAI,SAAS,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,SAAS,QAAQ;EACxE,CAAC;CACH,CAAC;CAEH,OAAO,cAAc,GAAG;EACtB,uBAAuB,UAAU,oBAAoB,qBAAqB,KAAK,CAAC;EAChF,2BAA2B,UAAU,oBAAoB,yBAAyB,KAAK,CAAC;CAC1F,CAAC;AACH,GACA,mBACF;AAEA,MAAa,kCACX,YACG,MAAM,OAAO,eAAe,8BAA8B,OAAO,CAAC"}
|
|
1
|
+
{"version":3,"file":"protocol.mjs","names":[],"sources":["../../../src/oauth/openid-client/protocol.ts"],"sourcesContent":["import { Cause, DateTime, Effect, Layer, Redacted, Schema } from \"effect\";\nimport * as client from \"openid-client\";\n\nimport { reportAuthFailure } from \"../../internal/diagnostics\";\nimport { RequestBindingFlowId } from \"../../operations/requestBinding\";\nimport { OAuthProtocol } from \"../OAuthProtocol\";\nimport { OAuthProviderKey } from \"../schema\";\nimport { OAuthProtocolRejected, OAuthRejected, OAuthUnavailable } from \"../signInErrors\";\nimport {\n OAuthCallbackId,\n OAuthCodeResponse,\n OAuthDisplayProfile,\n OAuthProtocolConfiguration,\n OAuthProtocolPreparation,\n OAuthTransactionSecrets,\n OAuthVerifiedExternalIdentity,\n} from \"../signInModels\";\nimport { snapshotOAuth } from \"../signInSnapshot\";\nimport { DefiniteTokenRejection, tokenCompatibility } from \"./compatibility\";\nimport {\n clientAuthentication,\n installConfigurations,\n makeAuthorizationParameters,\n type InstalledProvider,\n} from \"./configuration\";\nimport {\n type OpenIdClientConfigurationError,\n type OpenIdClientOAuthProtocolOptions,\n} from \"./models\";\nimport { decodeOidcProfile } from \"./profile\";\nimport { boundedFetch } from \"./transport\";\n\nconst beginInput = Schema.Struct({\n provider: OAuthProviderKey,\n callbackId: OAuthCallbackId,\n flowId: RequestBindingFlowId,\n});\n\nconst exchangeInput = Schema.toType(\n Schema.Struct({\n configuration: OAuthProtocolConfiguration,\n response: OAuthCodeResponse,\n secrets: OAuthTransactionSecrets,\n verificationStartedAt: Schema.DateTimeUtcFromMillis,\n }),\n);\n\nconst numericDate = Schema.Finite.check(Schema.isBetween({ minimum: 0, maximum: 8640000000000 }));\n\nconst claimsSchema = Schema.Struct({\n iss: Schema.String,\n sub: OAuthVerifiedExternalIdentity.fields.identity.fields.subject,\n aud: Schema.Union([\n Schema.String,\n Schema.Array(Schema.String).check(Schema.isMinLength(1), Schema.isMaxLength(1)),\n ]),\n azp: Schema.optionalKey(Schema.String),\n exp: numericDate,\n iat: numericDate,\n nbf: Schema.optionalKey(numericDate),\n auth_time: Schema.optionalKey(numericDate),\n});\n\nconst plainIdentitySchema = Schema.Struct({\n subject: OAuthVerifiedExternalIdentity.fields.identity.fields.subject,\n profile: Schema.optionalKey(OAuthDisplayProfile),\n});\n\nconst unavailable = () => OAuthUnavailable.make({});\nconst rejected = () => OAuthProtocolRejected.make({});\n\nconst unavailableOnDefect = <A, E, R>(effect: Effect.Effect<A, E, R>) =>\n effect.pipe(\n Effect.tapCause((cause) =>\n Cause.hasDies(cause) ? reportAuthFailure(\"oauth-protocol\", cause) : Effect.void,\n ),\n Effect.catchCause((cause): Effect.Effect<never, E | OAuthUnavailable> => {\n if (Cause.hasInterrupts(cause)) return Effect.interrupt;\n if (Cause.hasDies(cause)) return Effect.fail(unavailable());\n\n return Effect.failCause(cause);\n }),\n );\n\n/** Only precise claim errors and a fully parsed invalid_grant are definite.\n * INVALID_RESPONSE also covers signature/key/transport faults; keep it ambiguous. */\nconst grantError = (error: unknown) => {\n if (\n error instanceof DefiniteTokenRejection ||\n (error instanceof client.ClientError && error.cause instanceof DefiniteTokenRejection)\n )\n return rejected();\n if (\n error instanceof client.ClientError &&\n (error.code === \"OAUTH_JWT_CLAIM_COMPARISON_FAILED\" ||\n error.code === \"OAUTH_JWT_TIMESTAMP_CHECK_FAILED\")\n )\n return rejected();\n if (\n error instanceof client.ResponseBodyError &&\n error.status === 400 &&\n error.error === \"invalid_grant\"\n )\n return rejected();\n\n return unavailable();\n};\n\nconst privateConfiguration = <R>(\n entry: InstalledProvider<R>,\n timeout: number,\n fetch: client.CustomFetch,\n signal: AbortSignal,\n) => {\n const provider = entry.provider;\n const compatibility = provider.protocol === \"oauth\" ? provider[tokenCompatibility] : undefined;\n\n const configuration = new client.Configuration(\n entry.metadata,\n provider.clientId,\n {\n [client.clockSkew]: 0,\n [client.clockTolerance]: 0,\n ...(provider.protocol === \"oidc\"\n ? { id_token_signed_response_alg: provider.idTokenSignedResponseAlg }\n : {}),\n },\n clientAuthentication(provider.authentication),\n );\n\n configuration.timeout = timeout;\n const transport = boundedFetch(fetch, signal, entry.allowedUrls);\n\n configuration[client.customFetch] =\n compatibility === undefined\n ? transport\n : async (url, options) => {\n const response = await transport(url, options);\n\n if (url === new URL(entry.metadata.token_endpoint!).href) {\n const body: unknown = await response.clone().json();\n\n signal.throwIfAborted();\n compatibility.inspectReceipt(\n { body, status: response.status, contentType: response.headers.get(\"content-type\") },\n {\n scopes: provider.scopes,\n refreshRequired: false,\n operation: \"authorization_code\",\n },\n );\n signal.throwIfAborted();\n }\n\n return response;\n };\n if (provider.protocol === \"oidc\") client.enableNonRepudiationChecks(configuration);\n\n return configuration;\n};\n\nexport const makeOpenIdClientOAuthProtocol = Effect.fn(\"makeOpenIdClientOAuthProtocol\")(\n // Capture one provider table; each generation retains its own receipt rules.\n function* <R = never>(\n options: OpenIdClientOAuthProtocolOptions<R>,\n ): Effect.fn.Return<\n OAuthProtocol[\"Service\"],\n OpenIdClientConfigurationError | OAuthUnavailable,\n R\n > {\n const context = yield* Effect.context<R>();\n const { installed, fetch, timeoutSeconds } = yield* installConfigurations(options);\n\n const prepareAuthorization: OAuthProtocol[\"Service\"][\"prepareAuthorization\"] = Effect.fn(\n \"OpenIdClient.prepareAuthorization\",\n )(function* (input) {\n const request = yield* Schema.decodeEffect(beginInput)(input).pipe(\n Effect.mapError(() => OAuthRejected.make({})),\n );\n\n const entry = installed.find(\n ({ provider }) => provider.issuance === \"active\" && provider.provider === request.provider,\n );\n\n const provider = entry?.provider;\n\n const callback = provider?.callbacks.find(\n (candidate) => candidate.callbackId === request.callbackId,\n );\n\n if (entry === undefined || provider === undefined || callback === undefined)\n return yield* OAuthRejected.make({});\n\n const result = yield* Effect.tryPromise({\n try: async (signal) => {\n const configuration = privateConfiguration(entry, timeoutSeconds, fetch, signal);\n\n const state = client.randomState();\n const verifier = client.randomPKCECodeVerifier();\n const nonce = provider.protocol === \"oidc\" ? client.randomNonce() : undefined;\n const challenge = await client.calculatePKCECodeChallenge(verifier);\n\n signal.throwIfAborted();\n\n const url = client.buildAuthorizationUrl(\n configuration,\n makeAuthorizationParameters(provider, callback.redirectUri, {\n state,\n challenge,\n ...(nonce === undefined ? {} : { nonce }),\n }),\n );\n\n return {\n configuration: {\n provider: provider.provider,\n protocol: provider.protocol,\n configurationGeneration: provider.configurationGeneration,\n issuer: provider.issuer,\n responseIssuerMode: provider.responseIssuerMode,\n callbackId: callback.callbackId,\n redirectUri: callback.redirectUri,\n },\n authorizationUrl: Redacted.make(url.href),\n secrets: {\n namespace: \"effect-auth/oauth-transaction-secrets/v1\" as const,\n state: Redacted.make(state),\n pkceVerifier: Redacted.make(verifier),\n ...(nonce === undefined ? {} : { oidcNonce: Redacted.make(nonce) }),\n },\n };\n },\n catch: unavailable,\n });\n\n return yield* snapshotOAuth(OAuthProtocolPreparation, result);\n });\n\n const exchangeVerifiedIdentity: OAuthProtocol[\"Service\"][\"exchangeVerifiedIdentity\"] =\n Effect.fn(\"OpenIdClient.exchangeVerifiedIdentity\")(function* (input) {\n const request = yield* snapshotOAuth(exchangeInput, input);\n const saved = request.configuration;\n\n const entry = installed.find(\n ({ provider }) =>\n provider.provider === saved.provider &&\n provider.configurationGeneration === saved.configurationGeneration,\n );\n\n if (entry === undefined) return yield* unavailable();\n const provider = entry.provider;\n\n const callback = provider.callbacks.find(\n (candidate) => candidate.callbackId === saved.callbackId,\n );\n\n if (\n provider.protocol !== saved.protocol ||\n provider.issuer !== saved.issuer ||\n provider.responseIssuerMode !== saved.responseIssuerMode ||\n callback?.redirectUri !== saved.redirectUri\n )\n return yield* unavailable();\n if (\n (provider.protocol === \"oidc\") !== (request.secrets.oidcNonce !== undefined) ||\n Redacted.value(request.response.state) !== Redacted.value(request.secrets.state) ||\n (provider.responseIssuerMode === \"required\"\n ? request.response.issuer !== provider.issuer\n : request.response.issuer !== undefined)\n )\n return yield* rejected();\n const startedAt = DateTime.toEpochMillis(request.verificationStartedAt);\n\n if (startedAt < 0 || startedAt > DateTime.toEpochMillis(yield* DateTime.now))\n return yield* rejected();\n\n const exchanged = yield* Effect.tryPromise({\n try: async (signal) => {\n const configuration = privateConfiguration(entry, timeoutSeconds, fetch, signal);\n\n const currentUrl = new URL(saved.redirectUri);\n\n currentUrl.searchParams.set(\"code\", Redacted.value(request.response.code));\n currentUrl.searchParams.set(\"state\", Redacted.value(request.response.state));\n if (request.response.issuer !== undefined)\n currentUrl.searchParams.set(\"iss\", request.response.issuer);\n\n const tokens = await client.authorizationCodeGrant(\n configuration,\n currentUrl,\n {\n pkceCodeVerifier: Redacted.value(request.secrets.pkceVerifier),\n expectedState: Redacted.value(request.secrets.state),\n ...(provider.protocol === \"oidc\"\n ? {\n expectedNonce: Redacted.value(request.secrets.oidcNonce!),\n idTokenExpected: true,\n ...(provider.maxAgeSeconds === undefined\n ? {}\n : { maxAge: provider.maxAgeSeconds }),\n }\n : {}),\n },\n provider.tokenParameters,\n );\n\n signal.throwIfAborted();\n if (provider.protocol === \"oidc\")\n return { protocol: \"oidc\" as const, claims: tokens.claims() };\n if (tokens.token_type !== \"bearer\") throw unavailable();\n\n const response = await client.fetchProtectedResource(\n configuration,\n tokens.access_token,\n new URL(provider.identitySource.url),\n \"GET\",\n undefined,\n new Headers(provider.identitySource.headers),\n );\n\n signal.throwIfAborted();\n if (\n response.status !== 200 ||\n response.headers.get(\"content-type\")?.split(\";\", 1)[0]?.trim().toLowerCase() !==\n \"application/json\"\n )\n throw unavailable();\n const body: unknown = await response.json();\n\n signal.throwIfAborted();\n\n return { protocol: \"oauth\" as const, body };\n },\n catch: grantError,\n });\n\n if (exchanged.protocol === \"oidc\") {\n // oxlint-disable-next-line no-restricted-properties -- Project validated foreign ID-token claims into the adapter's stricter bounded profile.\n const claims = yield* Schema.decodeUnknownEffect(claimsSchema)(exchanged.claims).pipe(\n Effect.mapError(rejected),\n );\n\n const now = DateTime.toEpochMillis(yield* DateTime.now) / 1000;\n const audience = typeof claims.aud === \"string\" ? claims.aud : claims.aud[0];\n\n if (\n provider.protocol !== \"oidc\" ||\n claims.iss !== provider.issuer ||\n audience !== provider.clientId ||\n (claims.azp !== undefined && claims.azp !== provider.clientId) ||\n claims.exp <= now ||\n claims.iat > now ||\n (claims.nbf !== undefined && claims.nbf > now) ||\n (claims.auth_time !== undefined && claims.auth_time > now) ||\n (provider.maxAgeSeconds !== undefined &&\n (claims.auth_time === undefined ||\n claims.auth_time + provider.maxAgeSeconds < Math.floor(now)))\n )\n return yield* rejected();\n\n const profile = yield* decodeOidcProfile(exchanged.claims);\n\n return yield* snapshotOAuth(OAuthVerifiedExternalIdentity, {\n identity: { provider: provider.provider, issuer: provider.issuer, subject: claims.sub },\n ...(profile === undefined ? {} : { profile }),\n ...(claims.auth_time === undefined\n ? {}\n : {\n upstreamAuthenticatedAt: DateTime.makeUnsafe(\n Math.min(startedAt, claims.auth_time * 1000),\n ),\n }),\n });\n }\n if (provider.protocol !== \"oauth\") return yield* unavailable();\n\n const decoded = yield* Effect.suspend(() =>\n provider.identitySource.decodeIdentity(exchanged.body),\n ).pipe(\n Effect.provideContext(context),\n Effect.catchCause(\n (cause): Effect.Effect<never, OAuthProtocolRejected | OAuthUnavailable> => {\n if (Cause.hasInterrupts(cause))\n return reportAuthFailure(\"oauth-identity\", cause).pipe(\n Effect.andThen(Effect.interrupt),\n );\n if (\n cause.reasons.length === 1 &&\n cause.reasons[0]?._tag === \"Fail\" &&\n Schema.is(OAuthProtocolRejected)(cause.reasons[0].error)\n )\n return Effect.fail(rejected());\n\n return reportAuthFailure(\"oauth-identity\", cause).pipe(\n Effect.andThen(Effect.fail(unavailable())),\n );\n },\n ),\n );\n\n const identity = yield* Schema.decodeEffect(plainIdentitySchema)(decoded).pipe(\n Effect.mapError(rejected),\n );\n\n return yield* snapshotOAuth(OAuthVerifiedExternalIdentity, {\n identity: {\n provider: provider.provider,\n issuer: provider.issuer,\n subject: identity.subject,\n },\n ...(identity.profile === undefined ? {} : { profile: identity.profile }),\n });\n });\n\n return OAuthProtocol.of({\n prepareAuthorization: (input) => unavailableOnDefect(prepareAuthorization(input)),\n exchangeVerifiedIdentity: (input) => unavailableOnDefect(exchangeVerifiedIdentity(input)),\n });\n },\n unavailableOnDefect,\n);\n\nexport const openIdClientOAuthProtocolLayer = <R = never>(\n options: OpenIdClientOAuthProtocolOptions<R>,\n) => Layer.effect(OAuthProtocol, makeOpenIdClientOAuthProtocol(options));\n"],"mappings":";;;;;;;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M,QAAQ,WAAW,KACzB,MAAM,QAAQ,EAAE,EAAE,SAAS,UAC3B,OAAO,GAAG,qBAAqB,CAAC,CAAC,MAAM,QAAQ,EAAE,CAAC,KAAK,GAEvD,OAAO,OAAO,KAAK,SAAS,CAAC;GAE/B,OAAO,kBAAkB,kBAAkB,KAAK,CAAC,CAAC,KAChD,OAAO,QAAQ,OAAO,KAAK,YAAY,CAAC,CAAC,CAC3C;EACF,CACF,CACF;EAEA,MAAM,WAAW,OAAO,OAAO,aAAa,mBAAmB,CAAC,CAAC,OAAO,CAAC,CAAC,KACxE,OAAO,SAAS,QAAQ,CAC1B;EAEA,OAAO,OAAO,cAAc,+BAA+B;GACzD,UAAU;IACR,UAAU,SAAS;IACnB,QAAQ,SAAS;IACjB,SAAS,SAAS;GACpB;GACA,GAAI,SAAS,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,SAAS,QAAQ;EACxE,CAAC;CACH,CAAC;CAEH,OAAO,cAAc,GAAG;EACtB,uBAAuB,UAAU,oBAAoB,qBAAqB,KAAK,CAAC;EAChF,2BAA2B,UAAU,oBAAoB,yBAAyB,KAAK,CAAC;CAC1F,CAAC;AACH,GACA,mBACF;AAEA,MAAa,kCACX,YACG,MAAM,OAAO,eAAe,8BAA8B,OAAO,CAAC"}
|
|
@@ -44,6 +44,17 @@ declare const OAuthRegistrationIntent: Schema.Struct<{
|
|
|
44
44
|
readonly issuer: Schema.brand<Schema.String, "effect-auth/OAuthIssuer">;
|
|
45
45
|
readonly subject: Schema.NonEmptyString;
|
|
46
46
|
}>;
|
|
47
|
+
/** Original authenticated provider snapshot, available only to server-side
|
|
48
|
+
* provisioning authority. It is not caller-supplied registration data. */
|
|
49
|
+
readonly profile: Schema.optionalKey<Schema.Struct<{
|
|
50
|
+
readonly displayName: Schema.optionalKey<Schema.String>;
|
|
51
|
+
readonly handle: Schema.optionalKey<Schema.String>;
|
|
52
|
+
readonly avatarUrl: Schema.optionalKey<Schema.String>;
|
|
53
|
+
readonly profileUrl: Schema.optionalKey<Schema.String>;
|
|
54
|
+
readonly email: Schema.optionalKey<Schema.String>;
|
|
55
|
+
readonly emailVerified: Schema.optionalKey<Schema.Boolean>;
|
|
56
|
+
readonly providerData: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
|
|
57
|
+
}>>;
|
|
47
58
|
readonly verifiedAtMillis: Schema.Int;
|
|
48
59
|
readonly credentialDigest: Schema.brand<Schema.NonEmptyString, "effect-auth/TokenDigest">;
|
|
49
60
|
readonly issuedAtMillis: Schema.Int;
|
|
@@ -118,6 +129,17 @@ declare const OAuthRegistrationInspection: Schema.Struct<{
|
|
|
118
129
|
readonly issuer: Schema.brand<Schema.String, "effect-auth/OAuthIssuer">;
|
|
119
130
|
readonly subject: Schema.NonEmptyString;
|
|
120
131
|
}>;
|
|
132
|
+
/** Original authenticated provider snapshot, available only to server-side
|
|
133
|
+
* provisioning authority. It is not caller-supplied registration data. */
|
|
134
|
+
readonly profile: Schema.optionalKey<Schema.Struct<{
|
|
135
|
+
readonly displayName: Schema.optionalKey<Schema.String>;
|
|
136
|
+
readonly handle: Schema.optionalKey<Schema.String>;
|
|
137
|
+
readonly avatarUrl: Schema.optionalKey<Schema.String>;
|
|
138
|
+
readonly profileUrl: Schema.optionalKey<Schema.String>;
|
|
139
|
+
readonly email: Schema.optionalKey<Schema.String>;
|
|
140
|
+
readonly emailVerified: Schema.optionalKey<Schema.Boolean>;
|
|
141
|
+
readonly providerData: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
|
|
142
|
+
}>>;
|
|
121
143
|
readonly verifiedAtMillis: Schema.Int;
|
|
122
144
|
readonly credentialDigest: Schema.brand<Schema.NonEmptyString, "effect-auth/TokenDigest">;
|
|
123
145
|
readonly issuedAtMillis: Schema.Int;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TokenDigest } from "../Schema.mjs";
|
|
2
2
|
import { RequestBindingCredential, RequestBindingFlowId } from "../operations/requestBindingModels.mjs";
|
|
3
|
-
import { OAuthClaimId, OAuthCommandId, OAuthExternalIdentity, OAuthInstant, OAuthModuleId, OAuthSignInTransactionContext } from "./signInModels.mjs";
|
|
3
|
+
import { OAuthClaimId, OAuthCommandId, OAuthDisplayProfile, OAuthExternalIdentity, OAuthInstant, OAuthModuleId, OAuthSignInTransactionContext } from "./signInModels.mjs";
|
|
4
4
|
import { Schema } from "effect";
|
|
5
5
|
//#region src/oauth/registrationModels.ts
|
|
6
6
|
const OAuthRegistrationFingerprint = TokenDigest.check(Schema.isMaxLength(256));
|
|
@@ -30,6 +30,9 @@ const OAuthRegistrationIntent = Schema.Struct({
|
|
|
30
30
|
claimId: OAuthClaimId,
|
|
31
31
|
claimedAtMillis: OAuthInstant,
|
|
32
32
|
identity: OAuthExternalIdentity,
|
|
33
|
+
/** Original authenticated provider snapshot, available only to server-side
|
|
34
|
+
* provisioning authority. It is not caller-supplied registration data. */
|
|
35
|
+
profile: Schema.optionalKey(OAuthDisplayProfile),
|
|
33
36
|
verifiedAtMillis: OAuthInstant,
|
|
34
37
|
credentialDigest: OAuthRegistrationBearerDigest,
|
|
35
38
|
issuedAtMillis: OAuthInstant,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registrationModels.mjs","names":[],"sources":["../../src/oauth/registrationModels.ts"],"sourcesContent":["import { Schema } from \"effect\";\n\nimport { RequestBindingCredential, RequestBindingFlowId } from \"../operations/requestBinding\";\nimport { TokenDigest } from \"../Schema\";\nimport {\n OAuthClaimId,\n OAuthCommandId,\n OAuthExternalIdentity,\n OAuthInstant,\n OAuthModuleId,\n OAuthSignInTransactionContext,\n} from \"./signInModels\";\n\nexport const OAuthRegistrationFingerprint = TokenDigest.check(Schema.isMaxLength(256));\n\nexport const OAuthRegistrationBearerDigest = TokenDigest.check(\n Schema.isPattern(/^[A-Za-z0-9_-]{42}[AEIMQUYcgkosw048]$/),\n);\n\nexport const OAuthRegistrationReference = Schema.String.check(\n Schema.isPattern(/^[A-Za-z0-9_-]{43}$/),\n).pipe(Schema.brand(\"effect-auth/OAuthRegistrationReference\"));\n\nexport type OAuthRegistrationReference = typeof OAuthRegistrationReference.Type;\n\nexport const OAuthRegistrationCredential = Schema.RedactedFromValue(\n Schema.String.check(Schema.isPattern(/^[A-Za-z0-9_-]{43}$/)),\n);\n\nexport const OAuthRegistrationPolicy = Schema.Struct({\n lifetimeMillis: Schema.Int.check(Schema.isBetween({ minimum: 1000, maximum: 1800000 })),\n maximumVerificationAgeMillis: Schema.Int.check(\n Schema.isBetween({ minimum: 1000, maximum: 1800000 }),\n ),\n retentionMillis: Schema.Int.check(Schema.isBetween({ minimum: 120000, maximum: 2592000000 })),\n});\n\nexport type OAuthRegistrationPolicy = typeof OAuthRegistrationPolicy.Type;\n\n/** Immutable restricted capability. Application data is first bound by register,\n * never by the OAuth callback; this record contains no plaintext bearer or tokens. */\nexport const OAuthRegistrationIntent = Schema.Struct({\n namespace: Schema.Literal(\"effect-auth/oauth-registration-intent/v1\"),\n reference: OAuthRegistrationReference,\n context: OAuthSignInTransactionContext,\n claimId: OAuthClaimId,\n claimedAtMillis: OAuthInstant,\n identity: OAuthExternalIdentity,\n verifiedAtMillis: OAuthInstant,\n credentialDigest: OAuthRegistrationBearerDigest,\n issuedAtMillis: OAuthInstant,\n expiresAtMillis: OAuthInstant,\n retentionUntilMillis: OAuthInstant,\n});\n\nexport type OAuthRegistrationIntent = typeof OAuthRegistrationIntent.Type;\n\nexport const OAuthRegistrationRequired = Schema.TaggedStruct(\"RegistrationRequired\", {\n reference: OAuthRegistrationReference,\n expiresAtMillis: OAuthInstant,\n returnTarget: OAuthSignInTransactionContext.fields.returnTarget,\n});\n\nexport const OAuthRegistrationAccess = Schema.Struct({\n moduleId: OAuthModuleId,\n reference: OAuthRegistrationReference,\n flowId: RequestBindingFlowId,\n requestBindingVerifier: OAuthSignInTransactionContext.fields.requestBindingVerifier,\n requestBindingExpiresAtMillis: OAuthInstant,\n credentialDigest: OAuthRegistrationBearerDigest,\n nowMillis: OAuthInstant,\n});\n\nexport type OAuthRegistrationAccess = typeof OAuthRegistrationAccess.Type;\n\nexport const OAuthRegistrationPrivateInput = Schema.Struct({\n reference: OAuthRegistrationReference,\n flowId: RequestBindingFlowId,\n requestBinding: RequestBindingCredential,\n credential: OAuthRegistrationCredential,\n commandId: OAuthCommandId,\n});\n\nconst applicationBinding = { commandId: OAuthCommandId, fingerprint: OAuthRegistrationFingerprint };\nconst recovery = Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(256));\n\n/** A first accepted command atomically reaches one bound outcome. There is no\n * resettable intermediate state that permits a second provisioning attempt. */\nexport const OAuthRegistrationApplication = Schema.Union([\n Schema.TaggedStruct(\"Unbound\", {}),\n Schema.TaggedStruct(\"Registered\", applicationBinding),\n Schema.TaggedStruct(\"ProvisioningPending\", { ...applicationBinding, reference: recovery }),\n Schema.TaggedStruct(\"Rejected\", applicationBinding),\n]);\n\nexport const OAuthRegistrationInspection = Schema.Struct({\n intent: OAuthRegistrationIntent,\n application: OAuthRegistrationApplication,\n});\n\nexport type OAuthRegistrationInspection = typeof OAuthRegistrationInspection.Type;\n\nexport const OAuthRegistrationDecision = Schema.Union([\n Schema.TaggedStruct(\"Registered\", { replayed: Schema.Boolean }),\n Schema.TaggedStruct(\"ProvisioningPending\", { reference: recovery, replayed: Schema.Boolean }),\n Schema.TaggedStruct(\"Rejected\", {}),\n Schema.TaggedStruct(\"Conflict\", {}),\n]);\n\nexport type OAuthRegistrationDecision = typeof OAuthRegistrationDecision.Type;\n\nexport const OAuthRegistrationResult = Schema.Union([\n Schema.TaggedStruct(\"RegistrationAccepted\", {}),\n Schema.TaggedStruct(\"ProvisioningPending\", { reference: recovery }),\n]);\n"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"registrationModels.mjs","names":[],"sources":["../../src/oauth/registrationModels.ts"],"sourcesContent":["import { Schema } from \"effect\";\n\nimport { RequestBindingCredential, RequestBindingFlowId } from \"../operations/requestBinding\";\nimport { TokenDigest } from \"../Schema\";\nimport {\n OAuthClaimId,\n OAuthCommandId,\n OAuthDisplayProfile,\n OAuthExternalIdentity,\n OAuthInstant,\n OAuthModuleId,\n OAuthSignInTransactionContext,\n} from \"./signInModels\";\n\nexport const OAuthRegistrationFingerprint = TokenDigest.check(Schema.isMaxLength(256));\n\nexport const OAuthRegistrationBearerDigest = TokenDigest.check(\n Schema.isPattern(/^[A-Za-z0-9_-]{42}[AEIMQUYcgkosw048]$/),\n);\n\nexport const OAuthRegistrationReference = Schema.String.check(\n Schema.isPattern(/^[A-Za-z0-9_-]{43}$/),\n).pipe(Schema.brand(\"effect-auth/OAuthRegistrationReference\"));\n\nexport type OAuthRegistrationReference = typeof OAuthRegistrationReference.Type;\n\nexport const OAuthRegistrationCredential = Schema.RedactedFromValue(\n Schema.String.check(Schema.isPattern(/^[A-Za-z0-9_-]{43}$/)),\n);\n\nexport const OAuthRegistrationPolicy = Schema.Struct({\n lifetimeMillis: Schema.Int.check(Schema.isBetween({ minimum: 1000, maximum: 1800000 })),\n maximumVerificationAgeMillis: Schema.Int.check(\n Schema.isBetween({ minimum: 1000, maximum: 1800000 }),\n ),\n retentionMillis: Schema.Int.check(Schema.isBetween({ minimum: 120000, maximum: 2592000000 })),\n});\n\nexport type OAuthRegistrationPolicy = typeof OAuthRegistrationPolicy.Type;\n\n/** Immutable restricted capability. Application data is first bound by register,\n * never by the OAuth callback; this record contains no plaintext bearer or tokens. */\nexport const OAuthRegistrationIntent = Schema.Struct({\n namespace: Schema.Literal(\"effect-auth/oauth-registration-intent/v1\"),\n reference: OAuthRegistrationReference,\n context: OAuthSignInTransactionContext,\n claimId: OAuthClaimId,\n claimedAtMillis: OAuthInstant,\n identity: OAuthExternalIdentity,\n /** Original authenticated provider snapshot, available only to server-side\n * provisioning authority. It is not caller-supplied registration data. */\n profile: Schema.optionalKey(OAuthDisplayProfile),\n verifiedAtMillis: OAuthInstant,\n credentialDigest: OAuthRegistrationBearerDigest,\n issuedAtMillis: OAuthInstant,\n expiresAtMillis: OAuthInstant,\n retentionUntilMillis: OAuthInstant,\n});\n\nexport type OAuthRegistrationIntent = typeof OAuthRegistrationIntent.Type;\n\nexport const OAuthRegistrationRequired = Schema.TaggedStruct(\"RegistrationRequired\", {\n reference: OAuthRegistrationReference,\n expiresAtMillis: OAuthInstant,\n returnTarget: OAuthSignInTransactionContext.fields.returnTarget,\n});\n\nexport const OAuthRegistrationAccess = Schema.Struct({\n moduleId: OAuthModuleId,\n reference: OAuthRegistrationReference,\n flowId: RequestBindingFlowId,\n requestBindingVerifier: OAuthSignInTransactionContext.fields.requestBindingVerifier,\n requestBindingExpiresAtMillis: OAuthInstant,\n credentialDigest: OAuthRegistrationBearerDigest,\n nowMillis: OAuthInstant,\n});\n\nexport type OAuthRegistrationAccess = typeof OAuthRegistrationAccess.Type;\n\nexport const OAuthRegistrationPrivateInput = Schema.Struct({\n reference: OAuthRegistrationReference,\n flowId: RequestBindingFlowId,\n requestBinding: RequestBindingCredential,\n credential: OAuthRegistrationCredential,\n commandId: OAuthCommandId,\n});\n\nconst applicationBinding = { commandId: OAuthCommandId, fingerprint: OAuthRegistrationFingerprint };\nconst recovery = Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(256));\n\n/** A first accepted command atomically reaches one bound outcome. There is no\n * resettable intermediate state that permits a second provisioning attempt. */\nexport const OAuthRegistrationApplication = Schema.Union([\n Schema.TaggedStruct(\"Unbound\", {}),\n Schema.TaggedStruct(\"Registered\", applicationBinding),\n Schema.TaggedStruct(\"ProvisioningPending\", { ...applicationBinding, reference: recovery }),\n Schema.TaggedStruct(\"Rejected\", applicationBinding),\n]);\n\nexport const OAuthRegistrationInspection = Schema.Struct({\n intent: OAuthRegistrationIntent,\n application: OAuthRegistrationApplication,\n});\n\nexport type OAuthRegistrationInspection = typeof OAuthRegistrationInspection.Type;\n\nexport const OAuthRegistrationDecision = Schema.Union([\n Schema.TaggedStruct(\"Registered\", { replayed: Schema.Boolean }),\n Schema.TaggedStruct(\"ProvisioningPending\", { reference: recovery, replayed: Schema.Boolean }),\n Schema.TaggedStruct(\"Rejected\", {}),\n Schema.TaggedStruct(\"Conflict\", {}),\n]);\n\nexport type OAuthRegistrationDecision = typeof OAuthRegistrationDecision.Type;\n\nexport const OAuthRegistrationResult = Schema.Union([\n Schema.TaggedStruct(\"RegistrationAccepted\", {}),\n Schema.TaggedStruct(\"ProvisioningPending\", { reference: recovery }),\n]);\n"],"mappings":";;;;;AAcA,MAAa,+BAA+B,YAAY,MAAM,OAAO,YAAY,GAAG,CAAC;AAErF,MAAa,gCAAgC,YAAY,MACvD,OAAO,UAAU,uCAAuC,CAC1D;AAEA,MAAa,6BAA6B,OAAO,OAAO,MACtD,OAAO,UAAU,qBAAqB,CACxC,CAAC,CAAC,KAAK,OAAO,MAAM,wCAAwC,CAAC;AAI7D,MAAa,8BAA8B,OAAO,kBAChD,OAAO,OAAO,MAAM,OAAO,UAAU,qBAAqB,CAAC,CAC7D;AAEA,MAAa,0BAA0B,OAAO,OAAO;CACnD,gBAAgB,OAAO,IAAI,MAAM,OAAO,UAAU;EAAE,SAAS;EAAM,SAAS;CAAQ,CAAC,CAAC;CACtF,8BAA8B,OAAO,IAAI,MACvC,OAAO,UAAU;EAAE,SAAS;EAAM,SAAS;CAAQ,CAAC,CACtD;CACA,iBAAiB,OAAO,IAAI,MAAM,OAAO,UAAU;EAAE,SAAS;EAAQ,SAAS;CAAW,CAAC,CAAC;AAC9F,CAAC;;;AAMD,MAAa,0BAA0B,OAAO,OAAO;CACnD,WAAW,OAAO,QAAQ,0CAA0C;CACpE,WAAW;CACX,SAAS;CACT,SAAS;CACT,iBAAiB;CACjB,UAAU;;;CAGV,SAAS,OAAO,YAAY,mBAAmB;CAC/C,kBAAkB;CAClB,kBAAkB;CAClB,gBAAgB;CAChB,iBAAiB;CACjB,sBAAsB;AACxB,CAAC;AAID,MAAa,4BAA4B,OAAO,aAAa,wBA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: claim.claimedAtMillis,
|
|
52
52
|
identity: identity.identity,
|
|
53
|
+
...identity.profile === void 0 ? {} : { profile: identity.profile },
|
|
53
54
|
verifiedAtMillis,
|
|
54
55
|
credentialDigest: yield* credentialDigest(claim.flow.context.moduleId, reference, claim.flow.context.flowId, credential),
|
|
55
56
|
issuedAtMillis: now,
|