Skip to content

Commit

Permalink
make change work with existing oidc function
Browse files Browse the repository at this point in the history
  • Loading branch information
LiranCohen committed Oct 14, 2024
1 parent afc0c2a commit a6aaab0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 34 deletions.
12 changes: 10 additions & 2 deletions packages/agent/src/oidc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -788,11 +788,19 @@ async function submitAuthResponse(
selectedDid: string,
authRequest: Web5ConnectAuthRequest,
randomPin: string,
delegateBearerDid: BearerDid,
delegateGrants: DwnDataEncodedRecordsWriteMessage[]
agent: Web5Agent,
) {
const delegateBearerDid = await DidJwk.create();
const delegatePortableDid = await delegateBearerDid.export();

// Create the permission grants for the selected DID.
const delegateGrants = await Oidc.createAuthResponseGrants(
delegatePortableDid,
selectedDid,
authRequest.permissionRequests,
agent
);

logger.log('Generating auth response object...');
const responseObject = await Oidc.createResponseObject({
//* the IDP's did that was selected to be connected
Expand Down
37 changes: 5 additions & 32 deletions packages/agent/tests/connect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ describe('web5 connect', function () {
it('should send the encrypted jwe authresponse to the server', async () => {
sinon.stub(Oidc, 'createPermissionGrants').resolves(permissionGrants as any);
sinon.stub(CryptoUtils, 'randomBytes').returns(encryptionNonce);
sinon.stub(DidJwk, 'create').resolves(delegateBearerDid);

const formEncodedRequest = new URLSearchParams({
id_token : authResponseJwe,
Expand Down Expand Up @@ -402,8 +403,7 @@ describe('web5 connect', function () {
selectedDid,
authRequest,
randomPin,
delegateBearerDid,
delegatedGrants
testHarness.agent
);
expect(fetchSpy.calledOnce).to.be.true;
});
Expand Down Expand Up @@ -683,22 +683,13 @@ describe('web5 connect', function () {

const delegatePortableDid = await delegateBearerDid.export();

const delegatedGrants = await Oidc.createAuthResponseGrants(
await Oidc.createAuthResponseGrants(
delegatePortableDid,
providerIdentity.did.uri,
authRequest.permissionRequests,
testHarness.agent
);

// call submitAuthResponse
await Oidc.submitAuthResponse(
providerIdentity.did.uri,
authRequest,
randomPin,
delegateBearerDid,
delegatedGrants
);

// expect the process request to only be called once for ProtocolsQuery
expect(processDwnRequestStub.callCount).to.equal(1);
expect(processDwnRequestStub.firstCall.args[0].messageType).to.equal(DwnInterface.ProtocolsQuery);
Expand Down Expand Up @@ -746,22 +737,13 @@ describe('web5 connect', function () {
// generate the DID
const delegatePortableDid = await delegateBearerDid.export();

const delegatedGrants = await Oidc.createAuthResponseGrants(
await Oidc.createAuthResponseGrants(
delegatePortableDid,
providerIdentity.did.uri,
authRequest.permissionRequests,
testHarness.agent
);

// call submitAuthResponse
await Oidc.submitAuthResponse(
providerIdentity.did.uri,
authRequest,
randomPin,
delegateBearerDid,
delegatedGrants
);

// expect the process request to be called for query and configure
expect(processDwnRequestStub.callCount).to.equal(2);
expect(processDwnRequestStub.firstCall.args[0].messageType).to.equal(DwnInterface.ProtocolsQuery);
Expand All @@ -783,22 +765,13 @@ describe('web5 connect', function () {
const delegateBearerDid2 = await DidJwk.create();
const delegatePortableDid2 = await delegateBearerDid2.export();

const delegatedGrants2 = await Oidc.createAuthResponseGrants(
await Oidc.createAuthResponseGrants(
delegatePortableDid2,
providerIdentity.did.uri,
authRequest.permissionRequests,
testHarness.agent
);

// call submitAuthResponse
await Oidc.submitAuthResponse(
providerIdentity.did.uri,
authRequest,
randomPin,
delegateBearerDid2,
delegatedGrants2
);

// expect the process request to be called for query and configure
expect(processDwnRequestStub.callCount).to.equal(2);
expect(processDwnRequestStub.firstCall.args[0].messageType).to.equal(DwnInterface.ProtocolsQuery);
Expand Down

0 comments on commit a6aaab0

Please sign in to comment.