Skip to content

Commit

Permalink
remove vanilla authorize owner
Browse files Browse the repository at this point in the history
  • Loading branch information
LiranCohen committed Sep 8, 2024
1 parent 3a43054 commit d233df9
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 22 deletions.
18 changes: 1 addition & 17 deletions src/core/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,4 @@ export async function authenticate(authorizationModel: AuthorizationModel | unde
const ownerDelegatedGrant = await RecordsWrite.parse(authorizationModel.ownerDelegatedGrant);
await GeneralJwsVerifier.verifySignatures(ownerDelegatedGrant.message.authorization.signature, didResolver);
}
}

/**
* Authorizes owner authored message.
* @throws {DwnError} if fails authorization.
*/
export async function authorizeOwner(tenant: string, incomingMessage: MessageInterface<GenericMessage>): Promise<void> {
// if author is the same as the target tenant, we can directly grant access
if (incomingMessage.author === tenant) {
return;
} else {
throw new DwnError(
DwnErrorCode.AuthorizationAuthorNotOwner,
`Message authored by ${incomingMessage.author}, not authored by expected owner ${tenant}.`
);
}
}
}
1 change: 0 additions & 1 deletion src/core/dwn-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export enum DwnErrorCode {
AuthenticateJwsMissing = 'AuthenticateJwsMissing',
AuthenticateDescriptorCidMismatch = 'AuthenticateDescriptorCidMismatch',
AuthenticationMoreThanOneSignatureNotSupported = 'AuthenticationMoreThanOneSignatureNotSupported',
AuthorizationAuthorNotOwner = 'AuthorizationAuthorNotOwner',
AuthorizationNotGrantedToAuthor = 'AuthorizationNotGrantedToAuthor',
ComputeCidCodecNotSupported = 'ComputeCidCodecNotSupported',
ComputeCidMultihashNotSupported = 'ComputeCidMultihashNotSupported',
Expand Down
4 changes: 0 additions & 4 deletions tests/interfaces/messages-subscribe.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { authorizeOwner } from '../../src/core/auth.js';
import { MessagesSubscribe } from '../../src/interfaces/messages-subscribe.js';
import { DwnInterfaceName, DwnMethodName, Jws, TestDataGenerator, Time } from '../../src/index.js';

Expand All @@ -19,9 +18,6 @@ describe('MessagesSubscribe', () => {
expect(message.descriptor.method).to.eql(DwnMethodName.Subscribe);
expect(message.authorization).to.exist;
expect(message.descriptor.messageTimestamp).to.equal(timestamp);

// MessagesSubscribe authorizes against owner
await authorizeOwner(alice.did, messagesSubscribe);
});
});
});

0 comments on commit d233df9

Please sign in to comment.