Skip to content

Commit

Permalink
fix: allow to issuer identity to cancel pending JoinToIdentity auths
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorVicente committed Nov 19, 2020
1 parent 4357d54 commit 5ca310e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Expand Up @@ -169,6 +169,12 @@ describe('consumeJoinIdentityAuthorization procedure', () => {

result = await boundFunc(args);
expect(result).toBe(false);

args.accept = false;
args.authRequest.issuer = await mockContext.getCurrentIdentity();

result = await boundFunc(args);
expect(result).toBe(true);
});
});
});
13 changes: 10 additions & 3 deletions src/api/procedures/consumeJoinIdentityAuthorization.ts
Expand Up @@ -59,21 +59,28 @@ export async function prepareConsumeJoinIdentityAuthorization(
*/
export async function isAuthorized(
this: Procedure<ConsumeJoinIdentityAuthorizationParams>,
{ authRequest }: ConsumeJoinIdentityAuthorizationParams
{ authRequest, accept }: ConsumeJoinIdentityAuthorizationParams
): Promise<boolean> {
const { target } = authRequest;
const { target, issuer } = authRequest;
const { context } = this;

let condition;
let did: string;
const fetchDid = async (): Promise<string> => did || (await context.getCurrentIdentity()).did;

if (target instanceof Account) {
const { address } = context.getCurrentAccount();
condition = address === target.address;
} else {
const { did } = await context.getCurrentIdentity();
did = await fetchDid();
condition = did === target.did;
}

if (!accept) {
did = await fetchDid();
condition = condition || did === issuer.did;
}

return condition && !authRequest.isExpired();
}

Expand Down

0 comments on commit 5ca310e

Please sign in to comment.