Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaun Luttin committed Aug 30, 2018
1 parent 8c7bda1 commit 02bb758
Showing 1 changed file with 5 additions and 164 deletions.
169 changes: 5 additions & 164 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,177 +6,18 @@ This plugin adapts `oidc-client-js` to the Aurelia router. While it is possible

The demos have an example of how to configure everything.

### Smaller Demo(s)
### Smaller Demo(s) <- more up-to-date

https://github.com/aurelia-contrib/aurelia-open-id-connect-demos

### Larger, LIVE Demo

See it LIVE here: https://zamboni-app.azurewebsites.net
https://zamboni-app.azurewebsites.net

# Usage
# Installation

### Create an Aurelia application

We use the [Aurelia CLI][aurelia-cli] (we generally choose TypeScript and RequireJS).

au new

After creating the app, enter its directory and build.

cd aurelia-app
au build

### Install the aurelia-open-id-connect package

Install from NPM.

npm install --save aurelia-open-id-connect

Alternatively, install from GitHub [with an optional commit-ish].

npm install --save aurelia-contrib/aurelia-open-id-connect[#<commit-ish>]

Note: sometimes we need to install UNMET PEER DEPENDENCIES such as `babel-polyfill`.

### Add aurelia-open-id-connect to Aurelia

We use the Aurelia CLI, so we add the following to `aurelia.json` in a bundle.

{
"name": "aurelia-open-id-connect",
"path": "../node_modules/aurelia-open-id-connect/dist/amd",
"main": "index"
},
"oidc-client"

**Also** set `build.loader.plugins.stub = false` to load the plugin's HTML.
(TODO: Verify that this is necessary.)

### Configure the OpenID Connect client

Create a `src/open-id-connect-configuration.ts` file that specifies the Open ID Connect configuration. There is an [example here](/open-id-connect-configuration.ts.example).

In your `src/main.ts`, import the configuration file and `use` the plugin with a callback that returns the imported configuration.

import oidcConfig from "./open-id-connect-configuration";

aurelia.use
.plugin("aurelia-open-id-connect", () => oidcConfig);

### Change the Aurelia Container

If your application adds the `aurelia-app` property to the `body`...

<body aurelia-app="main">
<!-- Some placeholder content -->
<script src="scripts/main.js" data-main="aurelia-bootstrapper"/>
</body>

...then move the `aurelia-app` property to a wrapper `div` like this...

<body>
<div aurelia-app="main">
<!-- Some placeholder content -->
<script src="scripts/main.js" data-main="aurelia-bootstrapper"/>
</div>
</body>

Why?

> Aurelia was replacing the complete body element's contents, hence the disappearing iframe. The fix was to create a child div element where Aurelia puts its contents. Now everything works! ~ @ErikSchierboom
Thank you @RichiCoder1, @bewl, and @mttmccb for help to find the fix: https://github.com/aurelia-contrib/aurelia-open-id-connect/issues/4

### Add the user-block and router view.

Add the global resources to `app.html` (or to another appropriate view).

<template>
<open-id-connect-user-block></open-id-connect-user-block>
<open-id-connect-user-debug></open-id-connect-user-debug>
<ul>
<li repeat.for="nav of router.navigation | openIdConnectNavigationFilter:user">
<a href.bind="nav.href">${nav.title}</a>
</li>
</ul>
<router-view></router-view>
</template>

### Configure routing

Configure routing in the app.ts file and setup user-observation.

import { autoinject } from "aurelia-framework";
import { RouterConfiguration, Router } from "aurelia-router";
import { User } from "oidc-client";
import { OpenIdConnect, OpenIdConnectRoles } from "aurelia-open-id-connect";

@autoinject
export class App {

private router: Router;
private user: User;

constructor(private openIdConnect: OpenIdConnect) {
this.openIdConnect.observeUser((user: User) => this.user = user);
}

public configureRouter(routerConfiguration: RouterConfiguration, router: Router) {

// switch from hash (#) to slash (/) navigation
routerConfiguration.options.pushState = true;
routerConfiguration.title = "OpenID Connect Implicit Flow Demo";

// configure routes
routerConfiguration.map([
{
moduleId: "index",
name: "index",
route: ["", "index"],
title: "index",
nav: true,
},
{
moduleId: "private",
name: "private",
route: ["private"],
title: "private",
nav: true,
settings: {
roles: [OpenIdConnectRoles.Authenticated],
}
},
]);

this.openIdConnect.configure(routerConfiguration);
this.router = router;
}
}

### Add simple views that map to the routing.

index.html

<template></template>

index.ts

export class Index { }

private.html

<template></template>

private.ts

export class Private { }

### Run your application

npm install
au build
au run
yarn add aurelia-open-id-connect --save
npm install aurelia-open-id-connect --save

# Implicit Flow Implementor Guide

Expand Down

0 comments on commit 02bb758

Please sign in to comment.