-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use powertools for additional logging
- Loading branch information
1 parent
4fef2d2
commit 08d9c48
Showing
9 changed files
with
48 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,29 +1,41 @@ | ||
import { Logger } from '@aws-lambda-powertools/logger'; | ||
import { DynamoDBClient } from '@aws-sdk/client-dynamodb'; | ||
import { Response } from '@gemeentenijmegen/apigateway-http'; | ||
import { Session } from '@gemeentenijmegen/session'; | ||
import { OpenIDConnect } from '../code/OpenIDConnect'; | ||
|
||
export async function handleRequest(cookies: string, queryStringParamCode: string, queryStringParamState: string, dynamoDBClient: DynamoDBClient) { | ||
export async function handleRequest( | ||
cookies: string, | ||
queryStringParamCode: string, | ||
queryStringParamState: string, | ||
dynamoDBClient: DynamoDBClient, | ||
logger: Logger, | ||
) { | ||
let session = new Session(cookies, dynamoDBClient); | ||
await session.init(); | ||
if (session.sessionId === false) { | ||
logger.info('No session found'); | ||
return Response.redirect('/login'); | ||
} | ||
const state = session.getValue('state'); | ||
const OIDC = new OpenIDConnect(); | ||
try { | ||
const claims = await OIDC.authorize(queryStringParamCode, state, queryStringParamState); | ||
logger.debug('OIDC Claims', claims); // Log in debug to see the claims (set by LOG_LEVEL, see powertools) | ||
if (claims) { | ||
await session.createSession({ | ||
loggedin: { BOOL: true }, | ||
bsn: { S: claims.sub }, | ||
}); | ||
} else { | ||
logger.info('Authentication failed'); | ||
return Response.redirect('/login'); | ||
} | ||
} catch (error: any) { | ||
console.error(error.message); | ||
logger.info('Authentication failed'); | ||
logger.error(error.message); | ||
return Response.redirect('/login'); | ||
} | ||
logger.info('Authentication successful'); | ||
return Response.redirect('/', 302, session.getCookie()); | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.