mirror of
https://github.com/logto-io/logto.git
synced 2025-01-06 20:40:08 -05:00
fix(connector-alipay-web): rename input param name code to auth_code (#1015)
* fix(connector-alipay-web): rename input param name code to auth_code
This commit is contained in:
parent
d4f38bce2b
commit
1e27ee7630
2 changed files with 10 additions and 22 deletions
|
@ -147,7 +147,7 @@ describe('getUserInfo', () => {
|
|||
sign: '<signature>',
|
||||
});
|
||||
|
||||
const { id, name, avatar } = await alipayMethods.getUserInfo({ code: 'code' });
|
||||
const { id, name, avatar } = await alipayMethods.getUserInfo({ auth_code: 'code' });
|
||||
expect(id).toEqual('2088000000000000');
|
||||
expect(name).toEqual('PlayboyEric');
|
||||
expect(avatar).toEqual('https://www.alipay.com/xxx.jpg');
|
||||
|
@ -166,7 +166,7 @@ describe('getUserInfo', () => {
|
|||
sign: '<signature>',
|
||||
});
|
||||
|
||||
await expect(alipayMethods.getUserInfo({ code: 'wrong_code' })).rejects.toMatchError(
|
||||
await expect(alipayMethods.getUserInfo({ auth_code: 'wrong_code' })).rejects.toMatchError(
|
||||
new ConnectorError(ConnectorErrorCodes.SocialAccessTokenInvalid, 'Invalid auth token')
|
||||
);
|
||||
});
|
||||
|
@ -184,7 +184,7 @@ describe('getUserInfo', () => {
|
|||
sign: '<signature>',
|
||||
});
|
||||
|
||||
await expect(alipayMethods.getUserInfo({ code: 'wrong_code' })).rejects.toMatchError(
|
||||
await expect(alipayMethods.getUserInfo({ auth_code: 'wrong_code' })).rejects.toMatchError(
|
||||
new ConnectorError(ConnectorErrorCodes.General)
|
||||
);
|
||||
});
|
||||
|
@ -204,7 +204,7 @@ describe('getUserInfo', () => {
|
|||
sign: '<signature>',
|
||||
});
|
||||
|
||||
await expect(alipayMethods.getUserInfo({ code: 'code' })).rejects.toMatchError(
|
||||
await expect(alipayMethods.getUserInfo({ auth_code: 'code' })).rejects.toMatchError(
|
||||
new ConnectorError(ConnectorErrorCodes.InvalidResponse)
|
||||
);
|
||||
});
|
||||
|
@ -212,6 +212,6 @@ describe('getUserInfo', () => {
|
|||
it('should throw with other request errors', async () => {
|
||||
nock(alipayEndpointUrl.origin).post(alipayEndpointUrl.pathname).query(true).reply(500);
|
||||
|
||||
await expect(alipayMethods.getUserInfo({ code: 'code' })).rejects.toThrow();
|
||||
await expect(alipayMethods.getUserInfo({ auth_code: 'code' })).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -14,11 +14,11 @@ import {
|
|||
ValidateConfig,
|
||||
SocialConnector,
|
||||
GetConnectorConfig,
|
||||
codeDataGuard,
|
||||
} from '@logto/connector-types';
|
||||
import { assert } from '@silverhand/essentials';
|
||||
import dayjs from 'dayjs';
|
||||
import got from 'got';
|
||||
import { z } from 'zod';
|
||||
|
||||
import {
|
||||
alipayEndpoint,
|
||||
|
@ -35,19 +35,7 @@ import { signingParameters } from './utils';
|
|||
|
||||
export type { AlipayConfig } from './types';
|
||||
|
||||
type CodePayload = {
|
||||
auth_code: string;
|
||||
};
|
||||
|
||||
const parseCodeFromJson = (json: string): string => {
|
||||
try {
|
||||
const { auth_code } = JSON.parse(json) as CodePayload;
|
||||
|
||||
return auth_code;
|
||||
} catch {
|
||||
return json;
|
||||
}
|
||||
};
|
||||
const dataGuard = z.object({ auth_code: z.string() });
|
||||
|
||||
export default class AlipayConnector implements SocialConnector {
|
||||
public metadata: ConnectorMetadata = defaultMetadata;
|
||||
|
@ -86,7 +74,7 @@ export default class AlipayConnector implements SocialConnector {
|
|||
timestamp: dayjs().format(timestampFormat),
|
||||
version: '1.0',
|
||||
grant_type: 'authorization_code',
|
||||
code: parseCodeFromJson(code),
|
||||
code,
|
||||
charset: 'UTF8',
|
||||
...config,
|
||||
};
|
||||
|
@ -112,9 +100,9 @@ export default class AlipayConnector implements SocialConnector {
|
|||
};
|
||||
|
||||
public getUserInfo: GetUserInfo = async (data) => {
|
||||
const { code } = codeDataGuard.parse(data);
|
||||
const { auth_code } = dataGuard.parse(data);
|
||||
const config = await this.getConfig(this.metadata.id);
|
||||
const { accessToken } = await this.getAccessToken(code, config);
|
||||
const { accessToken } = await this.getAccessToken(auth_code, config);
|
||||
|
||||
assert(
|
||||
accessToken && config,
|
||||
|
|
Loading…
Reference in a new issue