Skip to content

Commit

Permalink
chore: Add prettier and execute it
Browse files Browse the repository at this point in the history
  • Loading branch information
manfredsteyer committed Mar 23, 2020
1 parent e2599e0 commit 0d15d6a
Show file tree
Hide file tree
Showing 81 changed files with 2,993 additions and 3,038 deletions.
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Add files here to ignore them from prettier formatting

/dist
/coverage
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
97 changes: 47 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Support for OAuth 2 and OpenId Connect (OIDC) in Angular. Already prepared for t

## Breaking Change in Version 9

With regards to tree shaking, beginning with version 9, the ``JwksValidationHandler`` has been moved to a library of its own. If you need it for implementing **implicit flow**, please install it using npm:
With regards to tree shaking, beginning with version 9, the `JwksValidationHandler` has been moved to a library of its own. If you need it for implementing **implicit flow**, please install it using npm:

```
npm i angular-oauth2-oidc-jwks --save
Expand All @@ -38,7 +38,6 @@ import { JwksValidationHandler } from 'angular-oauth2-oidc';

Please note, that this dependency is not needed for the **code flow**, which is nowadays the **recommended** flow for single page applications. This also results in smaller bundle sizes.


## Tested Environment

Successfully tested with **Angular 9** and its Router, PathLocationStrategy as well as HashLocationStrategy and CommonJS-Bundling via webpack. At server side we've used IdentityServer (.NET / .NET Core) and Redhat's Keycloak (Java).
Expand Down Expand Up @@ -66,14 +65,14 @@ Successfully tested with **Angular 9** and its Router, PathLocationStrategy as w
- The issues contain some ideas for PRs and enhancements (see labels)
- If you want to contribute to the docs, you can do so in the `docs-src` folder. Make sure you update `summary.json` as well. Then generate the docs with the following commands:

``` sh
```sh
npm install -g @compodoc/compodoc
npm run docs
```

## Features

- Logging in via Code Flow + PKCE
- Logging in via Code Flow + PKCE
- Hence, you are safe for the upcoming OAuth 2.1
- Logging in via Implicit Flow (where a user is redirected to Identity Provider)
- "Logging in" via Password Flow (where a user enters their password into the client)
Expand All @@ -90,17 +89,18 @@ Successfully tested with **Angular 9** and its Router, PathLocationStrategy as w

You can use the OIDC-Sample-Server used in our examples. It assumes, that your Web-App runs on http://localhost:4200

Username/Password:
- max/geheim
- bob/bob
- alice/alice
Username/Password:

- max/geheim
- bob/bob
- alice/alice

*clientIds:*
_clientIds:_

- spa (Code Flow + PKCE)
- implicit (implicit flow)

*redirectUris:*
_redirectUris:_

- localhost:[4200-4202]
- localhost:[4200-4202]/index.html
Expand Down Expand Up @@ -138,59 +138,58 @@ export class AppModule {
}
```

# Logging in
# Logging in

Since Version 8, this library supports code flow and [PKCE](https://tools.ietf.org/html/rfc7636) to align with the current draft of the [OAuth 2.0 Security Best Current Practice](https://tools.ietf.org/html/draft-ietf-oauth-security-topics-13) document. This is also the foundation of the upcoming OAuth 2.1.


To configure your solution for code flow + PKCE you have to set the `responseType` to `code`:

```TypeScript
import { AuthConfig } from 'angular-oauth2-oidc';
```TypeScript
import { AuthConfig } from 'angular-oauth2-oidc';

export const authCodeFlowConfig: AuthConfig = {
// Url of the Identity Provider
issuer: 'https://demo.identityserver.io',
export const authCodeFlowConfig: AuthConfig = {
// Url of the Identity Provider
issuer: 'https://demo.identityserver.io',

// URL of the SPA to redirect the user to after login
redirectUri: window.location.origin + '/index.html',
// URL of the SPA to redirect the user to after login
redirectUri: window.location.origin + '/index.html',

// The SPA's id. The SPA is registerd with this id at the auth-server
// clientId: 'server.code',
clientId: 'spa',
// The SPA's id. The SPA is registerd with this id at the auth-server
// clientId: 'server.code',
clientId: 'spa',

// Just needed if your auth server demands a secret. In general, this
// is a sign that the auth server is not configured with SPAs in mind
// and it might not enforce further best practices vital for security
// such applications.
// dummyClientSecret: 'secret',
// Just needed if your auth server demands a secret. In general, this
// is a sign that the auth server is not configured with SPAs in mind
// and it might not enforce further best practices vital for security
// such applications.
// dummyClientSecret: 'secret',

responseType: 'code',
responseType: 'code',

// set the scope for the permissions the client should request
// The first four are defined by OIDC.
// Important: Request offline_access to get a refresh token
// The api scope is a usecase specific one
scope: 'openid profile email offline_access api',
// set the scope for the permissions the client should request
// The first four are defined by OIDC.
// Important: Request offline_access to get a refresh token
// The api scope is a usecase specific one
scope: 'openid profile email offline_access api',

showDebugInformation: true,
showDebugInformation: true,

// Not recommented:
// disablePKCI: true,
};
```
// Not recommented:
// disablePKCI: true,
};
```

After this, you can initialize the code flow using:

```TypeScript
this.oauthService.initCodeFlow();
```
```TypeScript
this.oauthService.initCodeFlow();
```

There is also a convenience method `initLoginFlow` which initializes either the code flow or the implicit flow depending on your configuration.
There is also a convenience method `initLoginFlow` which initializes either the code flow or the implicit flow depending on your configuration.

```TypeScript
this.oauthService.initLoginFlow();
```
```TypeScript
this.oauthService.initLoginFlow();
```

Also -- as shown in the readme -- you have to execute the following code when bootstrapping to make the library to fetch the token:

Expand All @@ -199,17 +198,15 @@ this.oauthService.configure(authCodeFlowConfig);
this.oauthService.loadDiscoveryDocumentAndTryLogin();
```


### Skipping the Login Form

If you don't want to display a login form that tells the user that they are redirected to the identity server, you can use the convenience function ``this.oauthService.loadDiscoveryDocumentAndLogin();`` instead of ``this.oauthService.loadDiscoveryDocumentAndTryLogin();`` when setting up the library.
If you don't want to display a login form that tells the user that they are redirected to the identity server, you can use the convenience function `this.oauthService.loadDiscoveryDocumentAndLogin();` instead of `this.oauthService.loadDiscoveryDocumentAndTryLogin();` when setting up the library.

This directly redirects the user to the identity server if there are no valid tokens. Ensure you have your `issuer` set to your discovery document endpoint!


### Calling a Web API with an Access Token

You can automate this task by switching ``sendAccessToken`` on and by setting ``allowedUrls`` to an array with prefixes for the respective URLs. Use lower case for the prefixes.
You can automate this task by switching `sendAccessToken` on and by setting `allowedUrls` to an array with prefixes for the respective URLs. Use lower case for the prefixes.

```TypeScript
OAuthModule.forRoot({
Expand All @@ -228,7 +225,7 @@ See docs: https://manfredsteyer.github.io/angular-oauth2-oidc/docs/additional-do

## Routing

If you use the ``PathLocationStrategy`` (which is on by default) and have a general catch-all-route (``path: '**'``) you should be fine. Otherwise look up the section ``Routing with the HashStrategy`` in the [documentation](https://manfredsteyer.github.io/angular-oauth2-oidc/docs/).
If you use the `PathLocationStrategy` (which is on by default) and have a general catch-all-route (`path: '**'`) you should be fine. Otherwise look up the section `Routing with the HashStrategy` in the [documentation](https://manfredsteyer.github.io/angular-oauth2-oidc/docs/).

## Implicit Flow

Expand Down
26 changes: 7 additions & 19 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
"projects/lib/tsconfig.lib.json",
"projects/lib/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
"exclude": ["**/node_modules/**"]
}
}
}
Expand Down Expand Up @@ -131,9 +129,7 @@
"projects/sample/tsconfig.app.json",
"projects/sample/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
"exclude": ["**/node_modules/**"]
}
}
}
Expand All @@ -159,9 +155,7 @@
"projects/quickstart-demo/src/favicon.ico",
"projects/quickstart-demo/src/assets"
],
"styles": [
"projects/quickstart-demo/src/styles.css"
],
"styles": ["projects/quickstart-demo/src/styles.css"],
"scripts": []
},
"configurations": {
Expand Down Expand Up @@ -219,9 +213,7 @@
"projects/quickstart-demo/src/favicon.ico",
"projects/quickstart-demo/src/assets"
],
"styles": [
"projects/quickstart-demo/src/styles.css"
],
"styles": ["projects/quickstart-demo/src/styles.css"],
"scripts": []
}
},
Expand All @@ -233,9 +225,7 @@
"projects/quickstart-demo/tsconfig.spec.json",
"projects/quickstart-demo/e2e/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
"exclude": ["**/node_modules/**"]
}
},
"e2e": {
Expand Down Expand Up @@ -281,9 +271,7 @@
"projects/angular-oauth2-oidc-jwks/tsconfig.lib.json",
"projects/angular-oauth2-oidc-jwks/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
"exclude": ["**/node_modules/**"]
}
}
}
Expand All @@ -297,4 +285,4 @@
"cli": {
"analytics": false
}
}
}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
"scripts": {
"ng": "ng",
"start": "ng serve --project sample -o",
"build": "ng build --prod --project lib && npm run copy:readme && npm run docs",
"build:jwks": "ng build angular-oauth2-oidc-jwks --ts-config tsconfig.npm.json",
"build": "npm run prettier && ng build --prod --project lib && npm run copy:readme && npm run docs",
"build:jwks": "npm run prettier && ng build angular-oauth2-oidc-jwks --ts-config tsconfig.npm.json",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"tsc": "tsc",
"prettier": "prettier --write projects/**",
"docs": "npm run docs:build -- --disableCoverage --disablePrivate --disableInternal --includes docs-src",
"docs:build": "compodoc -p projects/lib/tsconfig.lib.json -n angular-oauth2-oidc -d docs --hideGenerator",
"docs:serve": "npm run docs:build -- -s",
Expand Down Expand Up @@ -64,7 +65,7 @@
"karma-jasmine": "~3.1.0",
"karma-jasmine-html-reporter": "^1.5.2",
"ng-packagr": "^9.0.0",
"prettier": "1.19.1",
"prettier": "^1.19.1",
"protractor": "~5.4.3",
"ts-node": "~8.6.2",
"tslint": "~5.18.0",
Expand Down
2 changes: 1 addition & 1 deletion projects/angular-oauth2-oidc-jwks/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# angular-oauth2-oidc-jwks

``JwksValidationHandler`` for ``angular-oauth2-odic``. Only needed for implicit flow.
`JwksValidationHandler` for `angular-oauth2-odic`. Only needed for implicit flow.
7 changes: 5 additions & 2 deletions projects/angular-oauth2-oidc-jwks/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (config) {
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
Expand All @@ -16,7 +16,10 @@ module.exports = function (config) {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../../coverage/angular-oauth2-oidc-jwks'),
dir: require('path').join(
__dirname,
'../../coverage/angular-oauth2-oidc-jwks'
),
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
},
Expand Down
6 changes: 2 additions & 4 deletions projects/angular-oauth2-oidc-jwks/ng-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@
"lib": {
"entryFile": "src/public-api.ts"
},
"whitelistedNonPeerDependencies": [
"jsrsasign"
]
}
"whitelistedNonPeerDependencies": ["jsrsasign"]
}
2 changes: 1 addition & 1 deletion projects/angular-oauth2-oidc-jwks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"dependencies": {
"jsrsasign": "^8.0.12"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import * as rs from 'jsrsasign';
import { AbstractValidationHandler, ValidationParams } from 'angular-oauth2-oidc';
import {
AbstractValidationHandler,
ValidationParams
} from 'angular-oauth2-oidc';

/**
* Validates the signature of an id_token against one
Expand Down Expand Up @@ -147,4 +150,4 @@ export class JwksValidationHandler extends AbstractValidationHandler {
}
return result;
}
}
}
10 changes: 2 additions & 8 deletions projects/angular-oauth2-oidc-jwks/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
"declaration": true,
"inlineSources": true,
"types": [],
"lib": [
"dom",
"es2018"
]
"lib": ["dom", "es2018"]
},
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
Expand All @@ -19,8 +16,5 @@
"strictInjectionParameters": true,
"enableResourceInlining": true
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
"exclude": ["src/test.ts", "**/*.spec.ts"]
}
14 changes: 3 additions & 11 deletions projects/angular-oauth2-oidc-jwks/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,8 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/spec",
"types": [
"jasmine",
"node"
]
"types": ["jasmine", "node"]
},
"files": [
"src/test.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
"files": ["src/test.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]
}
Loading

0 comments on commit 0d15d6a

Please sign in to comment.