Skip to content

Commit 11bce68

Browse files
Updating content, committing .htaccess, apache2 conf files and presignup trigger lambda function
1 parent e61dd99 commit 11bce68

File tree

7 files changed

+89
-28
lines changed

7 files changed

+89
-28
lines changed

src/app/f1/header/header.component.html

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
<nav class="navbar navbar-expand-sm bg-dark">
22
<ul class="navbar-nav mr-auto">
33
<li class="nav-item">
4-
<a class="nav-link" routerLink="/f1">HOME</a>
5-
</li>
6-
<li class="nav-item">
7-
<a class="nav-link" routerLink="">OTHER FLOWS</a>
4+
<a class="nav-link" routerLink="/">HOME</a>
85
</li>
96
</ul>
107
<ul class="navbar-nav ml-auto">

src/app/f1/index/index.component.html

-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
11
<app-header></app-header>
2-
<div class="card">
3-
<div class="card-body">
4-
<img src="assets/img/CognitoAuthnF1.png" />
5-
</div>
6-
</div>

src/app/f1/signup/signup.component.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
22
import { SignUpRequest } from '../../model/signuprequest';
33
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
44
import { AuthenticationService } from '../../services/authentication.service';
5+
import { Router } from '../../../../node_modules/@angular/router';
56

67
@Component({
78
selector: 'app-signup',
@@ -20,7 +21,14 @@ export class SignUpComponent implements OnInit {
2021
constructor(
2122
private formBuilder: FormBuilder,
2223
private authenticationService: AuthenticationService,
23-
) { }
24+
private router: Router,
25+
) {
26+
this.authenticationService.isAuthenticated().subscribe(isAuthenticated => {
27+
if (isAuthenticated) {
28+
this.router.navigate(['/f1/dashboard']);
29+
}
30+
})
31+
}
2432

2533
ngOnInit() {
2634
this.form = this.formBuilder.group({

src/app/index/index.component.html

+5-18
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,19 @@
11
<nav class="navbar navbar-expand-sm bg-dark">
2-
<ul class="navbar-nav ml-auto">
3-
<li class="nav-item">
4-
<a class="nav-link" routerLink="/f1">FLOW 1</a>
5-
</li>
6-
<li class="nav-item">
7-
<a class="nav-link" routerLink="">FLOW 2 (WIP)</a>
8-
</li>
9-
<li class="nav-item">
10-
<a class="nav-link" routerLink="">FLOW 3 (WIP)</a>
11-
</li>
12-
</ul>
132
</nav>
143
<section class="h-100">
154
<div class="container h-100">
165

17-
<h3>Flow 1: Simple flow without email/phone verification</h3>
18-
Run this flow <a routerLink="/f1">here</a>
6+
<h3>Simple flow without email/phone verification</h3>
7+
Run this flow <a routerLink="/f1/signup">here</a>
198
<ul>
209
<li>Users sign up with their email address. Phone number is optional.</li>
2110
<li>No verification of email address or phone number is done. </li>
2211
<li>Users are allowed to sign in with their email address without any verification.</li>
2312
<li>Auth Tokens are persisted as cookies which are used to remember the user across page refreshes and tab switches.</li>
2413
<li>Phone number, Name and password are displayed after the user signs in.</li>
25-
<li>Is unauthenticated users try to access a secure url (like /f1/dashboard, they are redirected to the corresponding sign in page)</li>
14+
<li>If unauthenticated users try to access a secure url (like /f1/dashboard, they are redirected to the corresponding sign in page)</li>
15+
<li>Sign-up/Sign-in with Google is also enabled</li>
2616
</ul>
27-
<h3>Flow 2: Email/phone verification after sign up</h3>
28-
WIP
29-
<h3>Flow 3: Sign up with any one of Email or phone, verification after sign up</h3>
30-
WIP
17+
<img src="assets/img/CognitoAuthnF1.png" />
3118
</div>
3219
</section>

src/assets/config/.htaccess

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Located at "/var/www/html/aws-cognito-authn/.htaccess"
2+
<IfModule mod_rewrite.c>
3+
RewriteEngine on
4+
RewriteCond %{REQUEST_FILENAME} -s [OR]
5+
RewriteCond %{REQUEST_FILENAME} -l [OR]
6+
RewriteCond %{REQUEST_FILENAME} -d
7+
RewriteRule ^.*$ - [NC,L]
8+
RewriteRule ^(.*) /aws-cognito-authn/index.html [NC,L]
9+
</IfModule>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
exports.handler = (event, context, callback) => {
2+
console.log('Received event:', JSON.stringify(event, null, 2))
3+
const modifiedEvent = event
4+
5+
// check that we're acting on the right trigger
6+
if (event.triggerSource.startsWith("PreSignUp")) {
7+
8+
// auto confirm the user
9+
modifiedEvent.response.autoConfirmUser = true
10+
11+
if (event.request.userAttributes.hasOwnProperty("email")) {
12+
modifiedEvent.response.autoVerifyEmail = true;
13+
}
14+
15+
// Set the phone number as verified if it is in the request
16+
if (event.request.userAttributes.hasOwnProperty("phone_number")) {
17+
modifiedEvent.response.autoVerifyPhone = true;
18+
}
19+
20+
callback(null, modifiedEvent)
21+
return
22+
}
23+
24+
// Throw an error if invoked from the wrong trigger
25+
callback(`Misconfigured Cognito Trigger ${ event.triggerSource }`)
26+
};
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Located at "/etc/apache2/sites-available/sarthakj178.com.conf"
2+
<VirtualHost *:80>
3+
ServerName sarthakj178.com
4+
ServerAlias sarthakj178.com
5+
ServerAdmin sarthakj178@gmail.com
6+
DocumentRoot /var/www/html
7+
Alias /aws-cognito-authn/ /var/www/html/aws-cognito-authn/
8+
<Directory /var/www/html/>
9+
Options +FollowSymlinks
10+
AllowOverride All
11+
Require all granted
12+
RewriteEngine On
13+
LogLevel alert rewrite:trace6
14+
</Directory>
15+
ErrorLog /tmp/error.log
16+
CustomLog /tmp/access.log combined
17+
18+
</VirtualHost>
19+
<VirtualHost *:443>
20+
ServerName sarthakj178.com
21+
ServerAlias sarthakj178.com
22+
ServerAdmin sarthakj178@gmail.com
23+
DocumentRoot /var/www/html
24+
DocumentRoot /var/www/html
25+
Alias /aws-cognito-authn/ /var/www/html/aws-cognito-authn/
26+
<Directory /var/www/html/>
27+
Options +FollowSymlinks
28+
AllowOverride All
29+
Require all granted
30+
RewriteEngine On
31+
LogLevel alert rewrite:trace6
32+
</Directory>
33+
34+
ErrorLog ${APACHE_LOG_DIR}/error.log
35+
CustomLog ${APACHE_LOG_DIR}/access.log combined
36+
SSLEngine on
37+
SSLCertificateFile /etc/apache2/ssl/apache.crt
38+
SSLCertificateKeyFile /etc/apache2/ssl/apache.key
39+
</VirtualHost>

0 commit comments

Comments
 (0)