generated from Borodutch/backend-starter
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add method for sing attestations for trusted resource
- Loading branch information
Showing
7 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Context, Next } from 'koa' | ||
import { forbidden } from '@hapi/boom' | ||
import verifyAuthToken from '@/helpers/verifyAuthToken' | ||
|
||
export default async function authenticate(ctx: Context, next: Next) { | ||
const authHeader = ctx.headers.authorization | ||
const token = authHeader && authHeader.split(' ')[1] | ||
const isValidToken = await verifyAuthToken(token) | ||
|
||
if (!isValidToken) throw forbidden() | ||
|
||
return next() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import env from '@/helpers/env' | ||
|
||
export default function verifyAuthToken(authToken?: string) { | ||
if (!authToken) return false | ||
try { | ||
return env.SECRET === authToken | ||
} catch (e) { | ||
console.log(e) | ||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { IsEnum, IsString } from 'amala' | ||
import AttestationType from '@/models/AttestationType' | ||
|
||
export default class { | ||
@IsString() | ||
hash!: string | ||
|
||
@IsEnum(AttestationType, { each: true }) | ||
types!: AttestationType[] | ||
} |