Verified Commit d0138816 authored by Raphael Ochsenbein's avatar Raphael Ochsenbein
Browse files

Make app compile / run && create api with express

parent 2e672cfd
// set dependencies
const express = require('express');
const app = express();
const jwt = require('express-jwt');
const jwksRsa = require('jwks-rsa');
const jwtAuthz = require('express-jwt-authz');
// Create middleware for checking the JWT
const checkJwt = jwt({
// Dynamically provide a signing key based on the kid in the header and the singing keys provided by the JWKS endpoint
secret: jwksRsa.expressJwtSecret({
cache: true,
rateLimit: true,
jwksRequestsPerMinute: 5,
jwksUri: `https://dev-l-3l8u04.eu.auth0.com/.well-known/jwks.json`
}),
// Validate the audience and the issuer
audience: 'https://dev-l-3l8u04.eu.auth0.com/api/v2/', // replace with your API's audience, available at Dashboard > APIs
issuer: 'https://dev-l-3l8u04.eu.auth0.com/',
algorithms: [ 'RS256' ] // we are using RS256 to sign our tokens
});
// create retrieve balance endpoint
app.get('/balance', checkJwt, jwtAuthz(['view:balance']), function (req, res) {
// code that retrieves the user's balance and sends it back to the calling app
res.status(201).send({message: "This is the GET /balance endpoint"});
});
// create transfer funds endpoint
app.post('/transfer', checkJwt, jwtAuthz(['transfer:funds']), function (req, res) {
// code that transfers funds from one account to another
res.status(201).send({message: "This is the POST /transfer endpoint"});
});
// launch the API Server at localhost:55001
app.listen(55001);
console.log('Listening on http://localhost:55001');
This diff is collapsed.
......@@ -3,20 +3,23 @@
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"start": "ng serve --aot",
"build": "ng build",
"test": "ng test",
"lint": "ng lint && npm run lint:sass",
"api": "node api/server.js",
"lint:sass": "sass-lint -c .sass-lint.yml -v -q",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "~7.2.0",
"@angular/cdk": "^7.3.3",
"@angular/common": "~7.2.0",
"@angular/compiler": "~7.2.0",
"@angular/core": "~7.2.0",
"@angular/forms": "~7.2.0",
"@angular/http": "^7.2.6",
"@angular/platform-browser": "~7.2.0",
"@angular/platform-browser-dynamic": "~7.2.0",
"@angular/router": "~7.2.0",
......@@ -26,6 +29,10 @@
"carbon-components": "^9.78.0",
"carbon-components-angular": "^2.34.0",
"core-js": "^2.5.4",
"express": "^4.16.4",
"express-jwt": "^5.3.1",
"express-jwt-authz": "^1.0.0",
"jwks-rsa": "^1.4.0",
"ng-oidc-client": "^1.0.5",
"oidc-client": "^1.6.1",
"rxjs": "~6.3.3",
......
<!--The content below is only a placeholder and can be replaced.-->
<div style="text-align:center">
<div>
<h1>
Welcome to {{ title }}!
</h1>
<img width="300" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
</div>
<h2>Here are some links to help you start: </h2>
<ul>
<li>
<h2><a target="_blank" rel="noopener" href="https://angular.io/tutorial">Tour of Heroes</a></h2>
</li>
<li>
<h2><a target="_blank" rel="noopener" href="https://angular.io/cli">CLI Documentation</a></h2>
</li>
<li>
<h2><a target="_blank" rel="noopener" href="https://blog.angular.io/">Angular blog</a></h2>
</li>
</ul>
<h2>Log In / Log Out</h2>
<button [ibmButton]="'primary'" [size]="'normal'" (click)="loginPopup()">Log In</button>
<button [ibmButton]="'danger--primary'" [size]="'normal'" (click)="logoutPopup()">Log Out</button>
<div class="notification-container"></div>
<ibm-toast [notificationObj]="{
type: 'error',
title: 'Sample toast',
subtitle: 'Sample subtitle message',
caption: 'Sample caption'
}"></ibm-toast>
h1,
h2 {
color: whitesmoke;
}
.notification-container {
}
import { Component } from '@angular/core';
import {OidcFacade} from 'ng-oidc-client';
import { OidcFacade} from 'ng-oidc-client';
import { NotificationService } from 'carbon-components-angular';
@Component({
selector: 'app-root',
......@@ -9,13 +10,25 @@ import {OidcFacade} from 'ng-oidc-client';
export class AppComponent {
title = 'openid-connect-playground';
constructor(private oidcFacade: OidcFacade) {}
constructor(private oidcFacade: OidcFacade, private notifications: NotificationService) {}
loginPopup() {
this.notifications.showNotification({
type: 'info',
title: 'Log In',
message: 'Logging in.',
target: '.notification-container',
});
this.oidcFacade.signinPopup();
}
logoutPopup() {
this.notifications.showNotification({
type: 'warn',
title: 'Log Out',
message: 'Logging out.',
target: '.notification-container',
});
this.oidcFacade.signoutPopup();
}
}
......
......@@ -12,6 +12,8 @@ import {HTTP_INTERCEPTORS} from '@angular/common/http';
import {OidcInterceptorService} from './oidc-interceptor.service';
import {OidcEffectsService} from './oidc-effects.service';
import {metaReducers} from './logout.metareducer';
import {ButtonModule, NotificationModule, NotificationService} from 'carbon-components-angular';
// Setup done according to https://www.npmjs.com/package/ng-oidc-client
......@@ -23,6 +25,8 @@ export const rootStore: ActionReducerMap<State> = {
router: routerReducer
};
// export const storage = new WebStorageStateStore({store: window.localStorage});
@NgModule({
declarations: [
AppComponent,
......@@ -33,8 +37,8 @@ export const rootStore: ActionReducerMap<State> = {
EffectsModule.forRoot([OidcEffectsService]),
NgOidcClientModule.forRoot({
oidc_config: {
authority: 'https://localhost:5001',
client_id: 'ng-oidc-client-identity',
authority: 'https://dev-l-3l8u04.eu.auth0.com',
client_id: 'FYg99lRIvbUwY4c0h5PkBArUOPnCcpH3',
redirect_uri: 'http://localhost:4200/callback.html',
response_type: 'id_token token',
scope: 'openid profile offline_access api1',
......@@ -42,13 +46,15 @@ export const rootStore: ActionReducerMap<State> = {
silent_redirect_uri: 'http://localhost:4200/renew-callback.html',
accessTokenExpiringNotificationTime: 10,
automaticSilentRenew: true,
userStore: new WebStorageStateStore({store: window.localStorage})
},
log: {
logger: console,
level: Log.NONE
// userStore: storage,
},
// log: {
// logger: window.console,
// level: 0,
// },
}),
ButtonModule,
NotificationModule,
],
providers: [
OidcGuardService,
......@@ -58,6 +64,7 @@ export const rootStore: ActionReducerMap<State> = {
multi: true
},
OidcEffectsService,
NotificationService,
],
bootstrap: [AppComponent]
})
......
import {ActionReducer, MetaReducer} from '@ngrx/store';
import {OidcActions} from 'ng-oidc-client';
import {State} from './app.module';
import {NotificationModule} from 'carbon-components-angular';
export function logout(reducer: ActionReducer<any>): ActionReducer<any> {
return (state: any, action: any) => {
......
......@@ -3,16 +3,25 @@ import {OidcActions} from 'ng-oidc-client';
import {Actions, Effect, ofType} from '@ngrx/effects';
import {Action} from '@ngrx/store';
import {Observable} from 'rxjs';
import {Router} from '@angular/router';
import {NotificationService} from 'carbon-components-angular';
export class OidcEffectsService {
constructor(private actions$: Actions, private router: Router) {}
constructor(
private actions$: Actions,
private notifications: NotificationService,
) {}
@Effect({ dispatch: false })
onUserSignedOut$: Observable<Action> = this.actions$.pipe(
ofType(OidcActions.OidcActionTypes.OnUserSignedOut),
tap(args => {
this.router.navigate(['/home']);
this.notifications.showNotification({
type: 'warn',
title: 'Log Out',
message: 'You have been logged out',
target: '.notification-container',
});
// this.router.navigate(['/home']);
})
);
}
......@@ -2,6 +2,9 @@
$font-path: '~carbon-components/src/globals/fonts';
@import "~carbon-components/scss/globals/scss/styles.scss";
@import "~@angular/cdk/overlay";
@include cdk-overlay;
body {
background: #1d1d1d;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment