Skip to content

Commit

Permalink
Creating An Official Release For Simple-Auth 1.x Series (#121)
Browse files Browse the repository at this point in the history
* 🎨 Introducing ember-suave #44

* 🎨 Adding prettier & commit hook #44

* 📝 Fixing docs.

* 📝 Fixing doc images with root-url.  Can't use alt attribute in `<img>` element.
  • Loading branch information
nadnoslen authored Nov 2, 2019
1 parent d91d38e commit decfaef
Show file tree
Hide file tree
Showing 31 changed files with 892 additions and 157 deletions.
22 changes: 7 additions & 15 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@ module.exports = {
ecmaVersion: 2018,
sourceType: 'module'
},
plugins: [
'ember'
],
extends: [
'eslint:recommended',
'plugin:ember/recommended'
],
plugins: ['ember', 'ember-suave'],
extends: ['eslint:recommended', 'plugin:ember/recommended', 'plugin:ember-suave/recommended'],
env: {
browser: true
},
rules: {
'ember/no-new-mixins': 'warn',
'arrow-parens': 'off',
'no-console': ['error', { allow: ['warn', 'error'] }],
'ember/no-jquery': 'error'
'ember/no-jquery': 'error',
'ember/no-new-mixins': 'warn',
'ember-suave/lines-between-object-properties': 'off'
},
overrides: [
// node files
Expand All @@ -33,12 +30,7 @@ module.exports = {
'config/**/*.js',
'tests/dummy/config/**/*.js'
],
excludedFiles: [
'addon/**',
'addon-test-support/**',
'app/**',
'tests/dummy/app/**'
],
excludedFiles: ['addon/**', 'addon-test-support/**', 'app/**', 'tests/dummy/app/**'],
parserOptions: {
sourceType: 'script'
},
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/tests/dummy/app/templates/**/*.md
3 changes: 3 additions & 0 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://prettier.io/docs/en/options.html
printWidth: 120
singleQuote: true
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# How To Contribute

## Installation
## Clone & Setup

* `git clone <repository-url>`
* `git clone [email protected]:cybertooth-io/ember-simple-auth-okta.git`
* `cd ember-simple-auth-okta`
* `yarn install`

Expand Down
7 changes: 3 additions & 4 deletions DEPLOYMENT.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
Deployment
==============================================================================
# Deployment

Typically run:

```bash
$ ember deploy production
$ ./node_modules/.bin/ember deploy production
```

If you need to force the current branch to be the LATEST:
```bash
$ ADDON_DOCS_UPDATE_LATEST=true ember deploy production
$ ADDON_DOCS_UPDATE_LATEST=true ./node_modules/.bin/ember deploy production
```
22 changes: 8 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,36 @@
ember-simple-auth-okta
==============================================================================
# ember-simple-auth-okta

Ember Simple Auth implementation wrapping `okta-auth-js`.

[![Maintainability](https://api.codeclimate.com/v1/badges/a5acd1c21cc1fddb227b/maintainability)](https://codeclimate.com/github/cybertooth-io/ember-simple-auth-okta/maintainability)
[![CircleCI](https://circleci.com/gh/cybertooth-io/ember-simple-auth-okta.svg?style=svg)](https://circleci.com/gh/cybertooth-io/ember-simple-auth-okta)
[![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=cybertooth-io/ember-simple-auth-okta)](https://dependabot.com/compatibility-score/?dependency-name=ember-simple-auth-okta&package-manager=npm_and_yarn)

Compatibility
------------------------------------------------------------------------------
## Compatibility

* Ember.js v3.4 or above
* Ember CLI v2.13 or above
* Node.js v8 or above

Docs
------------------------------------------------------------------------------
## Docs

[View the docs here](https://cybertooth-io.github.io/ember-simple-auth-okta/).

Dependencies
------------------------------------------------------------------------------
## Dependencies

I maintain a list of the [dependencies](DEPENDENCIES.md) that I've mixed into this addon project.


Contributing
------------------------------------------------------------------------------
## Contributing

See the [Contributing](CONTRIBUTING.md) guide for details.


License
------------------------------------------------------------------------------
## License

This project is licensed under the [MIT License](LICENSE.md).

Credits
------------------------------------------------------------------------------
## Credits

This addon was made possible with the support of:

Expand Down
45 changes: 25 additions & 20 deletions addon/authenticators/okta.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getOwner } from '@ember/application';
import { inject as service } from '@ember/service';
import OktaAuth from '@okta/okta-auth-js';
import { task, timeout } from 'ember-concurrency';
import BaseAuthenticator from 'ember-simple-auth/authenticators/base';
import OktaAuth from '@okta/okta-auth-js';

/**
* An __Ember Simple Auth__ `Authenticator` implementation that wraps Okta's
Expand All @@ -18,7 +18,6 @@ import OktaAuth from '@okta/okta-auth-js';
* @public
*/
export default class Okta extends BaseAuthenticator {

/**
* The Okta client instantiated in the constructor
* @type {OktaAuth}
Expand All @@ -41,23 +40,19 @@ export default class Okta extends BaseAuthenticator {
* @private
* TODO: Refactor @task syntax: https://github.com/cybertooth-io/ember-simple-auth-okta/issues/9
*/
@task(function* (exp) {
const wait = exp * 1000 - Date.now();
// eslint-disable-next-line generator-star-spacing
@task(function*(exp) {
let wait = exp * 1000 - Date.now();
console.warn('Scheduled authentication token refresh will occur at ', new Date(exp * 1000));

yield timeout(wait);

console.warn('Commencing refresh of the authentication tokens at ', new Date());
return getOwner(this).lookup('session:main').restore(); // TODO: this.restore() won't work...ideally use `this.trigger('sessionDataUpdated')` but the evented approach is not firing!
}) _renewTokensBeforeExpiry;

/**
* Instance Constructor/Initializer is responsible for creating an instance of the OktaAuth client.
*/
init() {
super.init(...arguments);
this._client = new OktaAuth(this.configuration.oktaConfigHash);
}
return getOwner(this)
.lookup('session:main')
.restore(); // TODO: this.restore() won't work...ideally use `this.trigger('sessionDataUpdated')` but the evented approach is not firing!
})
_renewTokensBeforeExpiry;

/**
*
Expand All @@ -66,7 +61,16 @@ export default class Okta extends BaseAuthenticator {
* @private
*/
static _isExpired(expiresAtInSeconds) {
return Date.now() >= (expiresAtInSeconds * 1000);
return Date.now() >= expiresAtInSeconds * 1000;
}

/**
* Instance Constructor/Initializer is responsible for creating an instance of the OktaAuth client.
* @public
*/
init() {
super.init(...arguments);
this._client = new OktaAuth(this.configuration.oktaConfigHash);
}

/**
Expand Down Expand Up @@ -94,7 +98,7 @@ export default class Okta extends BaseAuthenticator {
* @public
*/
async restore({ accessToken, idToken }) {
const data = { accessToken, idToken };
let data = { accessToken, idToken };
if (Okta._isExpired(data.accessToken.expiresAt)) {
console.warn('Attempting to renew tokens because the stored access token appears to have expired.');
data.accessToken = await this._client.token.renew(accessToken);
Expand Down Expand Up @@ -131,12 +135,12 @@ export default class Okta extends BaseAuthenticator {
* @public
*/
async authenticate(username, password) {
const sessionInfo = await this._client.signIn({ username, password });
const [accessToken] = await this._client.token.getWithoutPrompt({
let sessionInfo = await this._client.signIn({ username, password });
let [accessToken] = await this._client.token.getWithoutPrompt({
responseType: ['token'],
sessionToken: sessionInfo.sessionToken
});
const [idToken] = await this._client.token.getWithoutPrompt({
let [idToken] = await this._client.token.getWithoutPrompt({
responseType: ['id_token'],
scopes: this.configuration.idTokenScopes,
sessionToken: sessionInfo.sessionToken
Expand Down Expand Up @@ -170,7 +174,8 @@ export default class Okta extends BaseAuthenticator {
* @return {Ember.RSVP.Promise} A promise that when it resolves results in the session being invalidated
* @public
*/
invalidate(/*data*/) {
// eslint-disable-next-line no-unused-vars
invalidate(data) {
this._renewTokensBeforeExpiry.cancelAll();
return this._client.signOut();
}
Expand Down
6 changes: 3 additions & 3 deletions addon/mixins/adapters/authorization-header.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Mixin from '@ember/object/mixin';
import { inject as service } from '@ember/service';
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';
import Mixin from '@ember/object/mixin';

/**
* Mixes in the `Authentication` header with the __Bearer AcCeSsToKeN__.
Expand All @@ -13,8 +13,8 @@ import Mixin from '@ember/object/mixin';
export default Mixin.create(DataAdapterMixin, {
authorize(xhr) {
if (this.session.isAuthenticated) {
const accessToken = this.session.data.authenticated.accessToken.accessToken; // => your token!
const tokenType = this.session.data.authenticated.accessToken.tokenType; // => Bearer
let { accessToken } = this.session.data.authenticated.accessToken; // => your token!
let { tokenType } = this.session.data.authenticated.accessToken; // => Bearer

xhr.setRequestHeader(this.configuration.headerAuthorization, `${tokenType} ${accessToken}`);
}
Expand Down
19 changes: 9 additions & 10 deletions app/services/configuration.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import config from '../config/environment';
import Service from '@ember/service';
import { getWithDefault } from '@ember/object';
import Service from '@ember/service';
import config from '../config/environment';

/**
* A singleton service configuration that will pull in the `config/environment.js` properties and
Expand All @@ -12,21 +12,20 @@ import { getWithDefault } from '@ember/object';
* @public
*/
export default class ConfigurationService extends Service {

/** Constructor
* ---------------------------------------------------------------------------------------------------------------- */

init() {
super.init(...arguments);
this._oktaConfigHash = getWithDefault(
config, 'APP.ember-simple-auth-okta.config', { url: 'https://dev-000000.okta.com' }
);
this._oktaConfigHash = getWithDefault(config, 'APP.ember-simple-auth-okta.config', {
url: 'https://dev-000000.okta.com'
});
this._headerAuthorization = getWithDefault(
config, 'APP.ember-simple-auth-okta.headerAuthorization', 'Authorization'
);
this._idTokenScopes = getWithDefault(
config, 'APP.ember-simple-auth-okta.idTokenScopes', ['email', 'openid']
config,
'APP.ember-simple-auth-okta.headerAuthorization',
'Authorization'
);
this._idTokenScopes = getWithDefault(config, 'APP.ember-simple-auth-okta.idTokenScopes', ['email', 'openid']);
// TODO: need to capture the rest of the configuration attributes, assign them to member variables & create getter/setters
}

Expand Down
4 changes: 2 additions & 2 deletions blueprints/ember-simple-auth-okta/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
normalizeEntityName() {
}, // no-op since we're just adding dependencies

afterInstall: function (/*options*/) {
afterInstall(/* options*/) {
return this.addAddonsToProject({
packages: [
{ name: 'ember-auto-import' },
Expand All @@ -19,7 +19,7 @@ module.exports = {
}).then(() => {
return this.addPackagesToProject([
{ name: '@okta/okta-auth-js' }
])
]);
});
}
};
2 changes: 1 addition & 1 deletion config/deploy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env node */
'use strict';

module.exports = function (deployTarget) {
module.exports = function(deployTarget) {
let ENV = {
build: {},
git: {
Expand Down
12 changes: 9 additions & 3 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ module.exports = async function() {
{
name: 'ember-lts-2.12',
env: {
EMBER_OPTIONAL_FEATURES: JSON.stringify({ 'jquery-integration': true }),
EMBER_OPTIONAL_FEATURES: JSON.stringify({
'jquery-integration': true
})
},
npm: {
devDependencies: {
Expand All @@ -21,7 +23,9 @@ module.exports = async function() {
{
name: 'ember-lts-2.16',
env: {
EMBER_OPTIONAL_FEATURES: JSON.stringify({ 'jquery-integration': true }),
EMBER_OPTIONAL_FEATURES: JSON.stringify({
'jquery-integration': true
})
},
npm: {
devDependencies: {
Expand All @@ -33,7 +37,9 @@ module.exports = async function() {
{
name: 'ember-lts-2.18',
env: {
EMBER_OPTIONAL_FEATURES: JSON.stringify({ 'jquery-integration': true })
EMBER_OPTIONAL_FEATURES: JSON.stringify({
'jquery-integration': true
})
},
npm: {
devDependencies: {
Expand Down
2 changes: 1 addition & 1 deletion config/environment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

module.exports = function(/* environment, appConfig */) {
return { };
return {};
};
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@
"ember-source-channel-url": "^2.0.1",
"ember-try": "^1.2.1",
"eslint-plugin-ember": "^7.1.0",
"eslint-plugin-ember-suave": "^2.0.0",
"eslint-plugin-node": "^10.0.0",
"husky": "^3.0.9",
"lint-staged": "^9.4.2",
"loader.js": "^4.7.0",
"prettier": "^1.18.2",
"qunit-dom": "^0.9.0"
},
"engines": {
Expand All @@ -100,5 +104,11 @@
"configPath": "tests/dummy/config",
"demoURL": "https://cybertooth-io.github.io/ember-simple-auth-okta/"
},
"homepage": "https://cybertooth-io.github.io/ember-simple-auth-okta"
"homepage": "https://cybertooth-io.github.io/ember-simple-auth-okta",
"lint-staged": {
"src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"prettier --write",
"git add"
]
}
}
1 change: 1 addition & 0 deletions testem.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable camelcase */
module.exports = {
test_page: 'tests/index.html?hidepassed',
disable_watching: true,
Expand Down
5 changes: 5 additions & 0 deletions tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
env: {
embertest: true
}
};
Loading

0 comments on commit decfaef

Please sign in to comment.