Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const sdk = createPutioSdkPromiseClient();

const validation = await sdk.auth.validateToken(tokenToCheck);
const login = await sdk.auth.login({
callbackUrl,
clientId,
clientSecret,
password,
Expand Down
10 changes: 2 additions & 8 deletions src/core/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
validateToken,
verifyTOTP,
type GenerateTOTPResponse,
type LoginInput,
type LoginResponse,
type RegisterInput,
type TwoFactorRecoveryCodes,
Expand Down Expand Up @@ -664,14 +665,7 @@ export const createPutioSdkPromiseClient = (initialConfig: PutioSdkConfigShape =
getVoucher: (code: string) => provideSdk(config, getVoucher(code)),
grants: (): Promise<ReadonlyArray<OAuthApp>> => 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<LoginResponse> => provideSdk(config, login(input)),
login: (input: LoginInput): Promise<LoginResponse> => provideSdk(config, login(input)),
logout: () => provideSdk(config, logout()),
register: (input: RegisterInput) => provideSdk(config, register(input)),
resetPassword: (key: string, password: string) =>
Expand Down
3 changes: 2 additions & 1 deletion src/domains/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ describe("auth domain", () => {

const loginResult = await runSdkEffect(
login({
callbackUrl: "https://example.com/callback",
clientId: 42,
clientName: "Codex",
clientSecret: "secret",
Expand All @@ -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=");

Expand Down
21 changes: 13 additions & 8 deletions src/domains/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,15 @@ export type RecoveryCodesError = PutioOperationFailure<typeof RecoveryCodesError
export type RegenerateRecoveryCodesError = PutioOperationFailure<
typeof RegenerateRecoveryCodesErrorSpec
>;
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;
Expand All @@ -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<LoginResponse, LoginError, PutioSdkContext> =>
export const login = (
input: LoginInput,
): Effect.Effect<LoginResponse, LoginError, PutioSdkContext> =>
requestJson(LoginResponseSchema, {
auth: {
type: "basic",
Expand All @@ -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,
},
Expand Down