@velas/account-agent
Version:
sdk
33 lines (24 loc) • 1.07 kB
JavaScript
/*
* Bind scopes
*/
async function bindScopes(next) {
if (this.interaction.session && ((this.interaction.stage === 'consent' ) || this.interaction.stage === 'completed' )) {
const requested_scopes = new Set();
const scopes = this.interaction.params.scope;
scopes.push('openid');
scopes.forEach((scope) => requested_scopes.add(scope));
const accepted_scopes = this.interaction.session.acceptedScopesFor(this.interaction.params.client_id);
const rejected_scopes = this.interaction.session.rejectedScopesFor(this.interaction.params.client_id);
const new_scopes = [...requested_scopes].filter((x) => !accepted_scopes.has(x) && !rejected_scopes.has(x));
this.interaction.scopes = {
requested_scopes: [ ...requested_scopes ],
accepted_scopes: [ ...accepted_scopes ],
rejected_scopes: [ ...rejected_scopes ],
new_scopes,
}
} else {
this.interaction.scopes = undefined;
}
await next();
}
export default bindScopes;