-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9d3746
commit 2ec6042
Showing
10 changed files
with
46 additions
and
17 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
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
2 changes: 1 addition & 1 deletion
2
src/middlewares/authorization.test.ts → src/middlewares/authentication.test.ts
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,16 @@ | ||
import { AccountController } from '../controllers/AccountController' | ||
|
||
export const extractToken = (ctx: any): string => (ctx.header.token ? ctx.header.token : ctx.params.token) || '' | ||
|
||
export const Authentication = (accountController: AccountController) => async (ctx: any, next: any) => { | ||
const token = extractToken(ctx) | ||
|
||
if (token) { | ||
const { account, tokenData } = await accountController.authorizeRequest(token) | ||
|
||
ctx.state.tokenData = tokenData | ||
ctx.state.user = account | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,13 @@ | ||
import { AccountController } from '../controllers/AccountController' | ||
|
||
export const extractToken = (ctx: any): string => (ctx.header.token ? ctx.header.token : ctx.params.token) || '' | ||
|
||
export const Authorization = (accountController: AccountController) => async (ctx: any, next: any) => { | ||
export const Authorization = () => async (ctx: any, next: any) => { | ||
// TODO: add configuration to ctx in app.ts so middlewares have access. | ||
// This is needed until we can figure out how to restart vault between | ||
// individual tests. | ||
// Currently a hack used to prevent errors in integration tests. | ||
if (process.env.SKIP_VAULT === 'true') return (ctx.status = 404) | ||
|
||
const token = extractToken(ctx) | ||
|
||
const { account, tokenData } = await accountController.authorizeRequest(token) | ||
|
||
if (!account) return (ctx.status = 404) | ||
const { user } = ctx.state | ||
|
||
ctx.state.tokenData = tokenData | ||
ctx.state.user = account | ||
if (!user) return (ctx.status = 404) | ||
|
||
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