mirror of
https://github.com/logto-io/logto.git
synced 2024-12-23 20:33:16 -05:00
Merge pull request #968 from logto-io/sijie-alipay-code-json
feat(connector-alipay): parse code from json
This commit is contained in:
commit
6b53ed5f4f
2 changed files with 30 additions and 2 deletions
|
@ -41,6 +41,20 @@ import { signingParameters } from './utils';
|
||||||
|
|
||||||
export type { AlipayNativeConfig } from './types';
|
export type { AlipayNativeConfig } 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 AlipayNativeConnector implements SocialConnector {
|
export default class AlipayNativeConnector implements SocialConnector {
|
||||||
public metadata: ConnectorMetadata = defaultMetadata;
|
public metadata: ConnectorMetadata = defaultMetadata;
|
||||||
|
|
||||||
|
@ -72,7 +86,7 @@ export default class AlipayNativeConnector implements SocialConnector {
|
||||||
timestamp: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
timestamp: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
||||||
version: '1.0',
|
version: '1.0',
|
||||||
grant_type: 'authorization_code',
|
grant_type: 'authorization_code',
|
||||||
code,
|
code: parseCodeFromJson(code),
|
||||||
charset: 'UTF8',
|
charset: 'UTF8',
|
||||||
...config,
|
...config,
|
||||||
};
|
};
|
||||||
|
|
|
@ -35,6 +35,20 @@ import { signingParameters } from './utils';
|
||||||
|
|
||||||
export type { AlipayConfig } from './types';
|
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 {
|
export default class AlipayConnector implements SocialConnector {
|
||||||
public metadata: ConnectorMetadata = defaultMetadata;
|
public metadata: ConnectorMetadata = defaultMetadata;
|
||||||
|
|
||||||
|
@ -73,7 +87,7 @@ export default class AlipayConnector implements SocialConnector {
|
||||||
timestamp: this.getTimestamp(),
|
timestamp: this.getTimestamp(),
|
||||||
version: '1.0',
|
version: '1.0',
|
||||||
grant_type: 'authorization_code',
|
grant_type: 'authorization_code',
|
||||||
code,
|
code: parseCodeFromJson(code),
|
||||||
charset: 'UTF8',
|
charset: 'UTF8',
|
||||||
...config,
|
...config,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue