Skip to content

Commit

Permalink
fix: backend integration bugs and status messages
Browse files Browse the repository at this point in the history
  • Loading branch information
gitcommitshow committed Aug 1, 2022
1 parent f87b04f commit b38a90b
Show file tree
Hide file tree
Showing 19 changed files with 226 additions and 63 deletions.
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ app.use(function(req, res, next){
} else {
req.wantsJson = true;
}
console.debug(new Date().toString() + "Requested :: ", req.method, req.url);
console.debug(req.headers)
next();
})

Expand Down
8 changes: 4 additions & 4 deletions frontend/src/app/generate-token/generate-token.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ <h1 class="mb-5 heading">{{ "generate-token.create" | transloco }}</h1>

<hr>

<p class="justify-content-sm-between d-flex algo">
<div class="justify-content-sm-between d-flex algo">
<span>{{ "generate-token.algorithm" | transloco }}</span>
<a target="_blank" href="https://tools.ietf.org/html/rfc7518#section-3">Recommend algorithms</a>
</p>
</div>

<form #postForm="ngForm" (ngSubmit)="onCreateToken(postForm.value)">
<select [(ngModel)]="algo" name="algo" class="rectangle">
<option>HS256</option>
<option [selected]="true">RS256</option>
<option>ES256</option>
</select>

<p class="font-grey algo">{{"generate-token.data" | transloco}}</p>
<br/>
<div class="font-grey algo">{{"generate-token.data" | transloco}}</div>

<textarea [(ngModel)]="payloadValue" name="payload" class="rectangle-1 data1"></textarea>

Expand Down
4 changes: 3 additions & 1 deletion frontend/src/app/generate-token/generate-token.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import { StepService } from '../shared/services/step.service';
export class GenerateTokenComponent implements OnInit {

payloadValue = '{ "data" : "We raised series A" }'
algo ="RS256"
//TODO Update payload to {"data":"This is Pradeep with id xyz and he can access files owned by xyz","iat":1646252217,"exp":1646338617,"aud":"supertokens.com","iss":"Supertokens Inc","sub":"auth@supertokens.com"}

algo ="HS256"

@Input() token = ""

Expand Down
9 changes: 7 additions & 2 deletions frontend/src/app/send-jwt1/send-jwt1.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ <h1 class="mb-3 heading">{{ "send-jwt1.introduction" | transloco }}</h1>

<hr>

<div *ngIf="successToken" class="rectangle">
<div *ngIf="successText" class="rectangle">
<img src="assets/images/icon-check-square.png"/>
<span>{{ "send-jwt1.authenticated" | transloco | uppercase }}</span>
<span>{{ successText | transloco | uppercase }}</span>
</div>

<div *ngIf="errorText" class="rectangle error">
<img src="assets/images/icon-error.svg"/>
<span>{{ errorText | transloco | uppercase }}</span>
</div>

<div class="rectangle1">
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/app/send-jwt1/send-jwt1.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
}
}

.rectangle.error {
border: solid 1px rgba(255, 5, 5, 0.75);
background-color: rgba(209, 66, 31, 0.15);
}

.rectangle1 {
width: 668px;
height: 405px;
Expand All @@ -29,7 +34,7 @@
border: dashed 1px #505255;

.box {
width: 331.1px;
width: fit-content;
height: 30.5px;
padding: 6px 12.2px 8.5px 12.3px;
border-radius: 6px;
Expand Down
21 changes: 16 additions & 5 deletions frontend/src/app/send-jwt1/send-jwt1.component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { HttpErrorResponse } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { DemoService } from '../shared/services/demo.service';
Expand All @@ -17,16 +18,26 @@ export class SendJwt1Component implements OnInit {
) {
this.stepService.setStep(7)
}

ngOnInit(): void {
}
successToken = false

successText = "";
errorText = "";

sendJwtThroughRequestParameter(){
var myToken = localStorage.getItem('token')
this.demoService.remote().getFromRequestParameter(myToken).subscribe({
this.demoService.remote().sendTokenViaRequestParam(myToken).subscribe({
next: (success: any)=>{
this.successToken = true
}, error: (error: any) => {
console.error('error:', error);
console.log("success")
this.errorText = ""
this.successText = success && success.statusText ? success.statusText : "Authenticated"
},
complete: () => console.log("Sent token in request parameter"),
error: (error: HttpErrorResponse) => {
this.successText = "";
this.errorText = error.statusText || "Unsuccessful"
console.error('error:', error)
},
})
}
Expand Down
11 changes: 8 additions & 3 deletions frontend/src/app/send-jwt2/send-jwt2.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ <h1 class="mb-3 heading">{{ "send-jwt2.introduction" | transloco }}</h1>

<hr>

<div class="rectangle">
<img src="assets/images/icon-check-square.png"/>
<span>{{ "send-jwt2.authenticated" | transloco | uppercase }}</span>
<div *ngIf="successText" class="rectangle">
<img src="assets/images/icon-check-square.png"/>
<span>{{ successText | transloco | uppercase }}</span>
</div>

<div *ngIf="errorText" class="rectangle error">
<img src="assets/images/icon-error.svg"/>
<span>{{ errorText | transloco | uppercase }}</span>
</div>

<div class="rectangle1">
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/app/send-jwt2/send-jwt2.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
}
}

.rectangle.error {
border: solid 1px rgba(255, 5, 5, 0.75);
background-color: rgba(209, 66, 31, 0.15);
}

.rectangle1 {
width: 668px;
height: 419px;
Expand Down
12 changes: 9 additions & 3 deletions frontend/src/app/send-jwt2/send-jwt2.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export class SendJwt2Component implements OnInit {

token: any | null

successText = "";
errorText = "";

constructor(
private router : Router,
private demoService : DemoService,
Expand All @@ -26,12 +29,15 @@ export class SendJwt2Component implements OnInit {
}

sendJwtThroughBody(value: string){
this.token = value
this.demoService.remote().postFromBody(value).subscribe({
this.demoService.remote().sendTokenViaWebFormBody(value).subscribe({
next: (success: any)=>{
console.log('yes')
console.log('Authenticated')
this.errorText = "";
this.successText = success && success.statusText ? success.statusText : "You have been successfully authenticated"
}, error: (error: any) => {
console.error('error:', error);
this.successText = "";
this.errorText = error && error.statusText ? error.statusText : "Authentication failed"
},
})
}
Expand Down
28 changes: 14 additions & 14 deletions frontend/src/app/send-jwt3/send-jwt3.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ <h1 class="mb-3">{{ "send-jwt3.introduction" | transloco }}</h1>

<hr>

<div class="rectangle">
<div *ngIf="successText" class="rectangle">
<img src="assets/images/icon-check-square.png"/>
<span>{{ "send-jwt3.authenticated" | transloco | uppercase }}</span>
<span>{{ successText }}</span>
</div>

<div *ngIf="errorText" class="rectangle error">
<img src="assets/images/icon-error.svg"/>
<span>{{ errorText | transloco | uppercase }}</span>
</div>

<div class="rectangle1">
Expand All @@ -17,18 +22,13 @@ <h1>{{ "send-jwt3.request" | transloco }}</h1>
<div class="innerRectangle">
<div class="sampleContent">
<pre id="responseText">
<b>Sample Response</b>
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Cache-Control: no-store
Pragma: no-cache

{{'send-jwt3.openBracket' | transloco}}
"access_token":"mF_9.B5f-4.1JqM",
"token_type":"Bearer",
"expires_in":3600,
"refresh_token":"tGzv3JOkF0XG5Qx2TlKWIA"
{{ 'send-jwt3.closeBracket' | transloco}}
<b>Sample Request</b>
Request URL: /demo/protected/api/bearer
Request Method: GET

--Headers--
Content-Type: application/json
Authorization: "Bearer thetoken"
</pre>
</div>
<a href="#" class="edit">
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/app/send-jwt3/send-jwt3.component.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.rectangle {
width: 667px;
height: 53px;
height: fit-content;
padding: 16.5px 223.1px 15.5px 19.9px;
border-radius: 12px;
border: solid 1px rgba(0, 195, 15, 0.75);
Expand All @@ -20,6 +20,11 @@
}
}

.rectangle.error {
border: solid 1px rgba(255, 5, 5, 0.75);
background-color: rgba(209, 66, 31, 0.15);
}

.rectangle1 {
width: 668px;
height: 721px;
Expand All @@ -29,7 +34,7 @@
border: dashed 1px #505255;
.innerRectangle {
width: 604px;
height: 346px;
height: fit-content;
border-top-left-radius: 12px;
border-top-right-radius: 12px;
border: solid 1px #3c4053;
Expand Down
19 changes: 16 additions & 3 deletions frontend/src/app/send-jwt3/send-jwt3.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { StepService } from '../shared/services/step.service';
import { DemoService } from '../shared/services/demo.service'
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http';

@Component({
selector: 'app-send-jwt3',
Expand All @@ -11,6 +11,9 @@ import { HttpClient, HttpHeaders } from '@angular/common/http';
})
export class SendJwt3Component implements OnInit {

successText = "";
errorText = "";

constructor(
private router: Router,
private demoService: DemoService,
Expand All @@ -27,8 +30,18 @@ export class SendJwt3Component implements OnInit {
var headers = new HttpHeaders()
.set("Content-Type", "application\/json")
.set("Authorization", "Bearer " + token)
this.demoService.remote().getFromRequestHeader(headers).subscribe((response)=>{
console.log(response)
this.demoService.remote().sendTokenViaRequestHeader(headers).subscribe({
next: (success: any)=>{
console.log("success")
this.errorText = ""
this.successText = JSON.stringify(success, null, 4)
},
complete: () => console.log("Sent token in header"),
error: (error: HttpErrorResponse) => {
this.successText = ""
this.errorText = error.statusText || "Unsuccessful"
console.error('error:', error)
}
})
}

Expand Down
11 changes: 8 additions & 3 deletions frontend/src/app/send-jwt4/send-jwt4.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ <h1 class="mb-3">{{ "send-jwt4.introduction" | transloco }}</h1>

<hr>

<div class="rectangle">
<img src="assets/images/icon-check-square.png"/>
<span>{{ "send-jwt4.authenticated" | transloco | uppercase }}</span>
<div *ngIf="successText" class="rectangle">
<img src="assets/images/icon-check-square.png"/>
<span>{{ successText }}</span>
</div>

<div *ngIf="errorText" class="rectangle error">
<img src="assets/images/icon-error.svg"/>
<span>{{ errorText | transloco | uppercase }}</span>
</div>

<div class="rectangle1">
Expand Down
19 changes: 16 additions & 3 deletions frontend/src/app/send-jwt4/send-jwt4.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpHeaders } from '@angular/common/http';
import { HttpErrorResponse, HttpHeaders } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { DemoService } from '../shared/services/demo.service';
Expand All @@ -11,6 +11,9 @@ import { StepService } from '../shared/services/step.service';
})
export class SendJwt4Component implements OnInit {

successText = "";
errorText = "";

constructor(
private router : Router,
private demoService: DemoService,
Expand All @@ -27,8 +30,18 @@ export class SendJwt4Component implements OnInit {
}

getProtectedUserData(){
this.demoService.remote().webCookies().subscribe((success)=>{
console.log(success)
this.demoService.remote().webCookies().subscribe({
next: (success: any)=>{
console.log("success")
this.errorText = ""
this.successText = JSON.stringify(success, null, 4)
},
complete: () => console.log("Sent token in header"),
error: (error: HttpErrorResponse) => {
this.successText = ""
this.errorText = error.statusText || "Unsuccessful"
console.error('error:', error)
}
})
}

Expand Down
10 changes: 5 additions & 5 deletions frontend/src/app/shared/services/demo.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@ export class DemoService {
}
let httpRequest = this.http
return {
getFromRequestParameter(accessToken: any): Observable<any> {
sendTokenViaRequestParam(accessToken: any): Observable<any> {
let url = REMOTE_SERVER+ENDPOINTS.protected
let params = {
access_token: accessToken
}
return httpRequest.get<any>(url, {params: params});
},
postFromBody(body: any): Observable<any> {
sendTokenViaWebFormBody(body: any): Observable<any> {
let url = REMOTE_SERVER+ENDPOINTS.webForm
return httpRequest.post<any>(url, body.access_token);
return httpRequest.post<any>(url, body);
},
getFromRequestHeader(headers: any): Observable<any> {
sendTokenViaRequestHeader(headers: any): Observable<any> {
let url = REMOTE_SERVER+ENDPOINTS.bearer
return httpRequest.get<any>(url, {headers: headers});
},
login(body: any): Observable<any> {
let url = REMOTE_SERVER+ENDPOINTS.login
return httpRequest.post<any>(url, body);
},
webCookies(): Observable<any> {
sendTokenViaWebCookies(): Observable<any> {
let url = REMOTE_SERVER+ENDPOINTS.webCookies
return httpRequest.get<any>(url);
},
Expand Down
Loading

0 comments on commit b38a90b

Please sign in to comment.