From e33b8c32639eda78497411acd79b4f4d77fcceed Mon Sep 17 00:00:00 2001 From: Altay Date: Mon, 29 Jun 2026 14:14:27 +0300 Subject: [PATCH] feat(auth): pass callback url through login --- README.md | 1 + src/core/client.ts | 10 ++-------- src/domains/auth.spec.ts | 3 ++- src/domains/auth.ts | 21 +++++++++++++-------- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 5ccb28d..5b7fa16 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ const sdk = createPutioSdkPromiseClient(); const validation = await sdk.auth.validateToken(tokenToCheck); const login = await sdk.auth.login({ + callbackUrl, clientId, clientSecret, password, diff --git a/src/core/client.ts b/src/core/client.ts index 6f099c0..df87f03 100644 --- a/src/core/client.ts +++ b/src/core/client.ts @@ -42,6 +42,7 @@ import { validateToken, verifyTOTP, type GenerateTOTPResponse, + type LoginInput, type LoginResponse, type RegisterInput, type TwoFactorRecoveryCodes, @@ -664,14 +665,7 @@ export const createPutioSdkPromiseClient = (initialConfig: PutioSdkConfigShape = getVoucher: (code: string) => provideSdk(config, getVoucher(code)), grants: (): Promise> => provideSdk(config, grants()), linkDevice: (code: string) => provideSdk(config, linkDevice(code)), - login: (input: { - readonly clientId: string | number; - readonly clientSecret: string; - readonly password: string; - readonly username: string; - readonly clientName?: string; - readonly fingerprint?: string; - }): Promise => provideSdk(config, login(input)), + login: (input: LoginInput): Promise => provideSdk(config, login(input)), logout: () => provideSdk(config, logout()), register: (input: RegisterInput) => provideSdk(config, register(input)), resetPassword: (key: string, password: string) => diff --git a/src/domains/auth.spec.ts b/src/domains/auth.spec.ts index 7c9146d..8dc49aa 100644 --- a/src/domains/auth.spec.ts +++ b/src/domains/auth.spec.ts @@ -67,6 +67,7 @@ describe("auth domain", () => { const loginResult = await runSdkEffect( login({ + callbackUrl: "https://example.com/callback", clientId: 42, clientName: "Codex", clientSecret: "secret", @@ -76,7 +77,7 @@ describe("auth domain", () => { }), (request) => { expect(request.url).toBe( - "https://api.put.io/v2/oauth2/authorizations/clients/42/fingerprint-1?client_name=Codex&client_secret=secret", + "https://api.put.io/v2/oauth2/authorizations/clients/42/fingerprint-1?callback_url=https%3A%2F%2Fexample.com%2Fcallback&client_name=Codex&client_secret=secret", ); expect(getAuthorizationHeader(request)).toBe("Basic c2RrOnBhc3M="); diff --git a/src/domains/auth.ts b/src/domains/auth.ts index f2bbf5f..b93ee19 100644 --- a/src/domains/auth.ts +++ b/src/domains/auth.ts @@ -301,6 +301,15 @@ export type RecoveryCodesError = PutioOperationFailure; +export type LoginInput = { + readonly clientId: string | number; + readonly clientSecret: string; + readonly password: string; + readonly username: string; + readonly callbackUrl?: string; + readonly clientName?: string; + readonly fingerprint?: string; +}; export const buildAuthLoginUrl = (options: { readonly clientId: string | number; readonly redirectUri: string; @@ -317,14 +326,9 @@ export const buildAuthLoginUrl = (options: { response_type: options.responseType ?? "token", state: options.state, }); -export const login = (input: { - readonly clientId: string | number; - readonly clientSecret: string; - readonly password: string; - readonly username: string; - readonly clientName?: string; - readonly fingerprint?: string; -}): Effect.Effect => +export const login = ( + input: LoginInput, +): Effect.Effect => requestJson(LoginResponseSchema, { auth: { type: "basic", @@ -336,6 +340,7 @@ export const login = (input: { ? `/v2/oauth2/authorizations/clients/${encodePathSegment(input.clientId)}/${encodePathSegment(input.fingerprint)}` : `/v2/oauth2/authorizations/clients/${encodePathSegment(input.clientId)}`, query: { + callback_url: input.callbackUrl, client_name: input.clientName, client_secret: input.clientSecret, },