Skip to content

Commit

Permalink
fix: add correct grant type to authentication call (#61)
Browse files Browse the repository at this point in the history
* fix: add correct grant type to authentication call

* fix: remove unnecessary argument
  • Loading branch information
braaar authored Dec 4, 2023
1 parent a6284dd commit a26ee2b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/authentication/calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { buildCall } from 'typical-fetch';
import { z } from 'zod';
import { withZod } from '../common/utils.js';

export interface AuthorizationCodeInput {
export interface GetTokenInput {
code?: string;
clientId: string;
clientSecret: string;
Expand All @@ -26,7 +26,7 @@ export const authCodeResponseSchema = z
}));

export const getTokenCall = buildCall()
.args<{ input: AuthorizationCodeInput }>()
.args<{ input: GetTokenInput }>()
.path('/connect/token')
.headers({
'user-agent': 'abax-node-sdk/1.0',
Expand All @@ -36,7 +36,8 @@ export const getTokenCall = buildCall()
.body(({ input }) => {
const body = new URLSearchParams();

body.append('grant_type', 'authorization_code');
const grantType = input.code ? 'authorization_code' : 'client_credentials';
body.append('grant_type', grantType);
body.append('client_id', input.clientId);
body.append('client_secret', input.clientSecret);
if (input.code) {
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export * from './calls/get-equipment.js';
export * from './calls/list-equipment.js';
export * from './authentication/abax-auth.js';
export * from './authentication/types.js';
export type { AuthorizationCodeInput } from './authentication/calls.js';
export type { GetTokenInput } from './authentication/calls.js';
export * from './authentication/decode-abax-profile.js';

0 comments on commit a26ee2b

Please sign in to comment.