Skip to content

Commit

Permalink
Merge pull request #3534 from bright/cms/blog/aws-cdk-cognito-google-…
Browse files Browse the repository at this point in the history
…sign-in-nest-js

Automatically generated. Merged on Netlify CMS.
  • Loading branch information
izabelapawlik authored Dec 14, 2023
2 parents d41bafc + ba89be4 commit 16b4383
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions content/blog/aws-cdk-cognito-google-sign-in-nest-js.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ tags:
- aws-cdk
date: 2023-12-13T07:17:46.598Z
meaningfullyUpdatedAt: 2023-12-13T07:17:46.598Z
title: Google sign in with Cognito and Nest.js
title: Google Sign In with Cognito and Nest.js
layout: post
image: /images/openid-connect-logo.png
hidden: false
comments: true
published: true
language: en
---

If you want to implement Google sign-in, also called Google federation, and combine it with using AWS Cognito this blog
post if for you.
We'll use aws-cdk combined with Nest.js to achieve that.
Expand All @@ -23,13 +22,13 @@ We'll use aws-cdk combined with Nest.js to achieve that.
At Bright, we often keep infrastructure code next to application code.
Thus let's start with creating:

- Nest.js backend project
* Nest.js backend project

```shell
nest new backend
```

- aws-cdk infrastructure project
* aws-cdk infrastructure project

```shell
mkdir infrastrucutre
Expand Down Expand Up @@ -189,9 +188,9 @@ export class AuthController {
At the end of the sign-in flow our application we have `IdToken`, `AccessToken` and `RefreshToken`.
What we do at this stage depends on our needs. For example, we can:

- start a cookie-based session
- return `AccessToken` to frontend
- init user account configuration that do not fit into AWS Cognito
* start a cookie-based session
* return `AccessToken` to frontend
* init user account configuration that do not fit into AWS Cognito

## Combine Cognito with Passport Nest.js

Expand Down Expand Up @@ -233,7 +232,7 @@ export class NestPassportOAuthStrategy extends PassportStrategy(OAuth2Strategy)
## Provide users with login URL

With AWS Cognito we can use hosted pages. However, we often need to have a full control over the UI of our
application.
application.\
In such a case, we can craft a special URL that will trigger the sign in flow. Here's how to create the URL that will
trigger login with Google flow:

Expand All @@ -259,7 +258,7 @@ API credentials.

## ECS Task Definition

I'll spare you the details on how to run the Nest.js application in ECS. That's a topic for a separate blog post.
I'll spare you the details on how to run the Nest.js application in ECS. That's a topic for a separate blog post.\
However, there are a couple of important configuration options that you need to provide for the above snippets to work:

```typescript
Expand Down Expand Up @@ -288,3 +287,5 @@ The full code of the above setup is available in [GitHub](https://github.com/bri
In our example, AWS Cognito performs OpenID Connect exchange with Google. Our Nest.js application code only receives
information from Cognito. We can easily integrate new identity providers e.g. Facebook and our backend application code
would still work.

<EbookDynamic sectionTitle='Optimise sign-in experience of your app' ebookName='Optimise-Sign-In-Experience.pdf' ebookDescription='Download our free ebook and explore the best authentication methods.' ebookImage='/images/cover-sign-in-ebook.png' ebookAlt='ebook cover' />

0 comments on commit 16b4383

Please sign in to comment.