0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-20 21:32:31 -05:00

feat(connector-alipay): parse code from json

This commit is contained in:
wangsijie 2022-05-27 11:23:16 +08:00
parent 16449ad919
commit c248759b53
No known key found for this signature in database
GPG key ID: C72642FE24F7D42B

View file

@ -35,6 +35,20 @@ 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;
}
};
export default class AlipayConnector implements SocialConnector {
public metadata: ConnectorMetadata = defaultMetadata;
@ -73,7 +87,7 @@ export default class AlipayConnector implements SocialConnector {
timestamp: this.getTimestamp(),
version: '1.0',
grant_type: 'authorization_code',
code,
code: parseCodeFromJson(code),
charset: 'UTF8',
...config,
};