From 396dce8c3da6ad8bf82fde6f7c060b45205df5e1 Mon Sep 17 00:00:00 2001 From: Darcy Ye Date: Fri, 30 Dec 2022 16:05:32 +0800 Subject: [PATCH] feat: pass user agent to connector (#2770) --- .../src/routes/interaction/utils/social-verification.ts | 6 +++++- packages/core/src/routes/session/social.ts | 5 ++++- packages/toolkit/connector-kit/src/types.ts | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/core/src/routes/interaction/utils/social-verification.ts b/packages/core/src/routes/interaction/utils/social-verification.ts index 6963031f2..875527727 100644 --- a/packages/core/src/routes/interaction/utils/social-verification.ts +++ b/packages/core/src/routes/interaction/utils/social-verification.ts @@ -28,8 +28,12 @@ export const createSocialAuthorizationUrl = async ( assertThat(connector.type === ConnectorType.Social, 'connector.unexpected_type'); + const { + headers: { 'user-agent': userAgent }, + } = ctx.request; + return connector.getAuthorizationUri( - { state, redirectUri }, + { state, redirectUri, headers: { userAgent } }, async (connectorStorage: ConnectorSession) => assignConnectorSessionResult(ctx, provider, connectorStorage) ); diff --git a/packages/core/src/routes/session/social.ts b/packages/core/src/routes/session/social.ts index c41b3d8d2..d968d843d 100644 --- a/packages/core/src/routes/session/social.ts +++ b/packages/core/src/routes/session/social.ts @@ -52,13 +52,16 @@ export default function socialRoutes( }), }), async (ctx, next) => { + const { + headers: { 'user-agent': userAgent }, + } = ctx.request; await provider.interactionDetails(ctx.req, ctx.res); const { connectorId, state, redirectUri } = ctx.guard.body; assertThat(state && redirectUri, 'session.insufficient_info'); const connector = await getLogtoConnectorById(connectorId); assertThat(connector.type === ConnectorType.Social, 'connector.unexpected_type'); const redirectTo = await connector.getAuthorizationUri( - { state, redirectUri }, + { state, redirectUri, headers: { userAgent } }, async (connectorStorage: ConnectorSession) => assignConnectorSessionResult(ctx, provider, connectorStorage) ); diff --git a/packages/toolkit/connector-kit/src/types.ts b/packages/toolkit/connector-kit/src/types.ts index 2b453de71..25bd8dffe 100644 --- a/packages/toolkit/connector-kit/src/types.ts +++ b/packages/toolkit/connector-kit/src/types.ts @@ -166,6 +166,7 @@ export type GetAuthorizationUri = ( payload: { state: string; redirectUri: string; + headers?: { userAgent?: string }; }, setSession?: SetSession ) => Promise;