Skip to content

Commit

Permalink
fix: Cleanups (#314)
Browse files Browse the repository at this point in the history
* Get rid of `Authorize` button in Swagger UI

* Get rid of swagger `Authorize` from source code

* Add all the rest auth routes for API guarding

* Remove extra spaces in jsdoc swagger comments.

* Remove unused imports.

* Remove unused comments

* Get API guarding back:
- removed /credential-status/check
- removed /credential-status/search
- removed /did resolve the DID
- removed /presentation/verify

* Refactor auth flow and allow unauthorized users to make some actions

* Makes Identity initiating without race conditions

* Fix reassign condition

* Small fixes

---------

Co-authored-by: abdulla-ashurov <[email protected]>
Co-authored-by: DaevMithran <[email protected]>
  • Loading branch information
3 people authored Aug 2, 2023
1 parent 192d02f commit 3b8e4ad
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/controllers/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class CredentialController {
const { credential, policies } = request.body
const verifyStatus = request.query.verifyStatus === 'true' ? true : false
try {
const result = await Identity.unauthorized.verifyCredential(
const result = await new Identity(response.locals.customerId).agent.verifyCredential(
credential,
{
verifyStatus,
Expand Down Expand Up @@ -387,7 +387,7 @@ export class CredentialController {
const { presentation, verifierDid, policies } = request.body
const verifyStatus = request.query.verifyStatus === 'true' ? true : false
try {
const result = await Identity.unauthorized.verifyPresentation(
const result = await new Identity(response.locals.customerId).agent.verifyPresentation(
presentation,
{
verifyStatus,
Expand Down
4 changes: 2 additions & 2 deletions src/middleware/auth/credential-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export class CredentialAuthHandler extends AbstractAuthHandler {
this.registerRoute('/credential/reinstate', 'POST', 'reinstate:credential:testnet')
this.registerRoute('/credential/reinstate', 'POST', 'reinstate:credential:mainnet')
// true means allowUnauthorized
this.registerRoute('/credential/verify', 'POST', '', { allowUnauthorized: true })
this.registerRoute('/credential/verify', 'POST', '', { allowUnauthorized: true, skipNamespace: true })
}

public async handle(request: Request, response: Response): Promise<IAuthResponse>{
if (!request.path.includes('/credential')) {
if (!request.path.includes('/credential/')) {
return super.handle(request, response)
}
return this.commonPermissionCheck(request)
Expand Down
6 changes: 3 additions & 3 deletions src/middleware/auth/credential-status-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export class CredentialStatusAuthHandler extends AbstractAuthHandler {
this.registerRoute('/credential-status/update', 'POST', 'update:credential-status:testnet')
this.registerRoute('/credential-status/update', 'POST', 'update:credential-status:mainnet')
// true means allowUnauthorized
this.registerRoute('/credential-status/search', 'GET', '', { allowUnauthorized: true })
this.registerRoute('/credential-status/check', 'POST', '', { allowUnauthorized: true })
this.registerRoute('/credential-status/search', 'GET', '', { allowUnauthorized: true, skipNamespace: true })
this.registerRoute('/credential-status/check', 'POST', '', { allowUnauthorized: true, skipNamespace: true })
}
public async handle(request: Request, response: Response): Promise<IAuthResponse> {
if (!request.path.includes('/credential-status')) {
if (!request.path.includes('/credential-status/')) {
return super.handle(request, response)
}
return this.commonPermissionCheck(request)
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/auth/did-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class DidAuthHandler extends AbstractAuthHandler {
this.registerRoute('/did/deactivate', 'POST', 'deactivate:did:testnet')
this.registerRoute('/did/deactivate', 'POST', 'deactivate:did:mainnet')
// true means allowUnauthorized
this.registerRoute('/did/(.*)', 'GET', '', { allowUnauthorized: true })
this.registerRoute('/did/(.*)', 'GET', '', { allowUnauthorized: true, skipNamespace: true })
}

public async handle(request: Request, response: Response): Promise<IAuthResponse> {
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/auth/presentation-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class PresentationAuthHandler extends AbstractAuthHandler {
constructor () {
super()
// true means allowUnauthorized
this.registerRoute('/presentation/verify', 'POST', '', { allowUnauthorized: true })
this.registerRoute('/presentation/verify', 'POST', '', { allowUnauthorized: true, skipNamespace: true })
}
public async handle(request: Request, response: Response): Promise<IAuthResponse> {
if (!request.path.includes('/presentation')) {
Expand Down

0 comments on commit 3b8e4ad

Please sign in to comment.