Skip to content

Commit

Permalink
Finish cleanup for v2
Browse files Browse the repository at this point in the history
  • Loading branch information
awlayton committed Apr 14, 2022
1 parent 11c9230 commit 8d8804b
Show file tree
Hide file tree
Showing 17 changed files with 1,265 additions and 670 deletions.
16 changes: 14 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
dist
.test
coverage
.yarn
.pnp.*
node_modules
yarn-cache
services-available

LICENSE

tags*
.history

**/yarn.lock
**/yarn-error.log
**/.yarn/*
**/.pnp.*

act
13 changes: 11 additions & 2 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ plugins:
parser: '@typescript-eslint/parser'

parserOptions:
extraFileExtensions: ['.ts', '.mts', '.mjs']
ecmaVersion: 2020
project: './tsconfig.eslint.json'
project:
- './src/tsconfig.browser.json'
- './src/tsconfig.node.json'
- './test/tsconfig.json'
- './tsconfig.eslint.json'

overrides:
- files: '*.ts'
Expand All @@ -46,7 +51,11 @@ overrides:
- prettier
parserOptions:
ecmaVersion: 2020
project: './tsconfig.eslint.json'
project:
- './src/tsconfig.browser.json'
- './src/tsconfig.node.json'
- './test/tsconfig.json'
- './tsconfig.eslint.json'
rules:
'@typescript-eslint/naming-convention':
[
Expand Down
57 changes: 26 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,15 @@ Can be used both in NodeJS and in the browser.
For use in NodeJS or with something like webpack:

```sh
yarn add OADA/oada-id-client-js
```

You can also get it from a CDN in browser:

```html
<script src="https://unpkg.com/@oada/oada-id-client"></script>
yarn add @oada/id-client
```

### Browser Code Generation

The code to use in the browser can be generated with the following command:

```sh
$ npm run bundle
yarn bundle
```

This will create the file `dist/bundle.js`.
Expand Down Expand Up @@ -61,7 +55,7 @@ parameter with a name of `domain`.

`options` object containing at least the following properties:

- [`metadata`][] object containg client metadata,
- [`metadata`][] object containing client metadata,
or string of a [`software_statement`][] JWT
- `privateKey`
- `pem` string or buffer containing your client's PEM encoded private RSA
Expand All @@ -73,8 +67,8 @@ parameter with a name of `domain`.

#### Usage Example

```javascript
var options = {
```typescript
const options = {
metadata: {
/* See spec linked above */
},
Expand Down Expand Up @@ -103,7 +97,7 @@ parameter with a name of `domain`.

`options` object containing at least the following properties:

- [`metadata`][] object containg client metadata,
- [`metadata`][] object containing client metadata,
or string of a [`software_statement`][] JWT
- `privateKey`
- `pem` string or buffer containing your client's PEM encoded private RSA
Expand All @@ -117,8 +111,8 @@ parameter with a name of `domain`.

#### Usage Example

```javascript
var options = {
```typescript
const options = {
metadata: {
/* See spec linked above */
},
Expand All @@ -145,7 +139,7 @@ another to receive `getAccessToken` redirects.

#### Usage Example

```javascript
```typescript
// Handle ID token redirects
app.use(
'/url/referenced/by/getIDToken/redirect_uri',
Expand Down Expand Up @@ -191,7 +185,7 @@ an OADA identity provider.

`options` object containing at least the following properties:

- [`metadata`][] object containg client metadata,
- [`metadata`][] object containing client metadata,
or string of a [`software_statement`][] JWT
- `params` [Optional OpenID Connect parameters][oidparams] placed in `params` as
string properties will be used (e.g. `display`, `prompt`, `login_hint`)
Expand All @@ -203,14 +197,14 @@ string properties will be used (e.g. `display`, `prompt`, `login_hint`).

#### Usage Example

```javascript
var options = {
```typescript
const options = {
metadata: {
/* See spec linked above */
},
};

var domain; // Set domain based on text box, dropdown, etc.
const domain = /* Set domain based on text box, dropdown, etc. */;

oadaIdClient.getIDToken(domain, options, function (err, idToken) {
if (err) {
Expand All @@ -234,7 +228,7 @@ parameter with a name of `domain`.

`options` object containing at least the following properties:

- [`metadata`][] object containg client metadata,
- [`metadata`][] object containing client metadata,
or string of a [`software_statement`][] JWT
- [`scope`][] space separated string of OAuth scopes for the request access
token to have.
Expand All @@ -245,20 +239,20 @@ parameter with a name of `domain`.

#### Usage Example

```javascript
var options = {
```typescript
const options = {
metadata: {
/* See spec linked above */
},
scope: 'some.oada.defined.scope',
};

var domain; // Set domain based on text box, dropdown, etc.
const domain = /* Set domain based on text box, dropdown, etc. */;

oadaIdClient.getAccessToken(domain, options, function (err, accessToken) {
if (err) {
return console.dir(err);
} // Soemthing went wrong
} // Something went wrong

console.dir(accessToken);
});
Expand Down Expand Up @@ -295,13 +289,14 @@ Not yet documented.
[in browser example]: examples/browser-client/

1. [OpenID Connect Core 1.0](http://openid.net/specs/openid-connect-core-1_0.html)
[oidparams]: http://openid.net/specs/openid-connect-core-1_0.html#AuthRequest "OpenID Connect Core 1.0 Section 3.1.2.1"
1. [OAuth 2.0 Authorization Framework](http://tools.ietf.org/html/rfc6749 'RFC6749')
[`client_id`]: http://tools.ietf.org/html/rfc6749#section-2.2 "RFC6794 Section 2.2"
[`redirect_uri`]: http://tools.ietf.org/html/rfc6749#section-3.1.2 "RFC6794 Section 3.1.2"
[`scope`]: http://tools.ietf.org/html/rfc6749#section-3.3 "RFC6794 Section 3.3"
1. [JSON Web Key (JWK) Draft 31](https://tools.ietf.org/html/draft-ietf-jose-json-web-key-31)
[`kid`]: https://tools.ietf.org/html/draft-ietf-jose-json-web-key-31#section-4.5 "JWK Section 4.5"
1. [OAuth 2.0 Dynamic Client Registration Protocol](https://tools.ietf.org/html/draft-ietf-oauth-dyn-reg)
[`metadata`]: https://tools.ietf.org/html/draft-ietf-oauth-dyn-reg#section-2 "oauth-dyn-reg Section 2"
[`software_statement`]: https://tools.ietf.org/html/draft-ietf-oauth-dyn-reg#section-2.3 "oauth-dyn-reg Section 2.3"

[oidparams]: http://openid.net/specs/openid-connect-core-1_0.html#AuthRequest 'OpenID Connect Core 1.0 Section 3.1.2.1'
[`client_id`]: http://tools.ietf.org/html/rfc6749#section-2.2 'RFC6794 Section 2.2'
[`redirect_uri`]: http://tools.ietf.org/html/rfc6749#section-3.1.2 'RFC6794 Section 3.1.2'
[`scope`]: http://tools.ietf.org/html/rfc6749#section-3.3 'RFC6794 Section 3.3'
[`kid`]: https://tools.ietf.org/html/draft-ietf-jose-json-web-key-31#section-4.5 'JWK Section 4.5'
[`metadata`]: https://tools.ietf.org/html/draft-ietf-oauth-dyn-reg#section-2 'oauth-dyn-reg Section 2'
[`software_statement`]: https://tools.ietf.org/html/draft-ietf-oauth-dyn-reg#section-2.3 'oauth-dyn-reg Section 2.3'
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* Copyright 2014 Open Ag Data Alliance
/**
* @license
* Copyright 2014-2022 Open Ag Data Alliance
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,21 +15,31 @@
* limitations under the License.
*/

/*
/* eslint-disable no-secrets/no-secrets */

/**
* Express server to test the server client part of the library
* @packageDocumentation
*/
'use strict';

var fs = require('fs');
var express = require('express');
var app = express();
var login = require('../../').middleware;
import fs from 'fs';
import path from 'path';
import url from 'url';

import express from 'express';

import { middleware as login } from '../..';

var pem = fs.readFileSync(__dirname + '/privkey.pem');
var kid = '1234';
var key = { pem: pem, kid: kid };
const app = express();

var options = {
// eslint-disable-next-line security/detect-non-literal-fs-filename
const pem = fs.readFileSync(
`${path.dirname(url.fileURLToPath(import.meta.url))}/privkey.pem`
);
const kid = '1234';
const key = { pem, kid };

const options = {
metadata:
'eyJqa3UiOiJodHRwczovL2lkZW50aXR5Lm9hZGEtZGV2LmNvbS9jZXJ0cyIsI' +
'mtpZCI6ImtqY1NjamMzMmR3SlhYTEpEczNyMTI0c2ExIiwidHlwIjoiSldUIi' +
Expand Down Expand Up @@ -62,12 +74,8 @@ app.use('/who', login.getIDToken('identity.oada-dev.com', options));
app.use('/get', login.getAccessToken('identity.oada-dev.com', options));

app.use('/redirect', login.handleRedirect());
app.use('/redirect', function (req, res) {
res.json(req.token);
app.use('/redirect', (request, response) => {
response.json(request.token);
});

if (require.main === module) {
app.listen(3007);
}

module.exports = app;
app.listen(3007);
14 changes: 9 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* Copyright 2014 Open Ag Data Alliance
/**
* @license
* Copyright 2014-2022 Open Ag Data Alliance
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,14 +15,16 @@
* limitations under the License.
*/

module.exports = require('./src/core');
/* eslint-disable import/no-commonjs, unicorn/prefer-module */
module.exports = require('./dist/core');

module.exports.browser = require('./src/browser');
module.exports.browser = require('./dist/browser');

// You can only include this in node because the "open" library that it uses
// fails to compile in the browser
// eslint-disable-next-line no-undef
if (typeof process !== 'undefined' && typeof window === 'undefined') {
module.exports.node = require('./src/node-browser');
module.exports.node = require('./dist/node');
}

module.exports.middleware = require('./src/middleware');
module.exports.middleware = require('./dist/middleware');
Loading

0 comments on commit 8d8804b

Please sign in to comment.