@velas/account-agent
Version:
sdk
36 lines (26 loc) • 933 B
JavaScript
import { nanoid } from 'nanoid';
import ttl from '../helper/ttl';
/*
* Issue AuthorizationCode
*/
async function AuthorizationCode(next) {
const jti = nanoid();
const code = {
jti,
auth_time: this.interaction.params.auth_time,
account: this.interaction.session.account,
client_id: this.interaction.client.client_id,
auth_challenge: this.interaction.params.challenge,
code_challenge: this.interaction.params.code_challenge,
grant_id: this.interaction.params.code_challenge,
scopes: this.interaction.scopes.requested_scopes,
session_id: this.interaction.session.op_key,
};
await this.provider.storage.setItem(`${'Code'}:${jti}`, code, {
issuer: 'agent',
expires: new Date().getTime() + ttl.code
});
this.code = code;
await next();
};
export default AuthorizationCode;