npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-icis-auth

v0.8.0

Published

Authentication engine for ICIS applications

Downloads

6

Readme

Ember-icis-auth

This Ember CLI addon gives you everything you need to start authenticating against our identity service which will allow you access to our service layer via CORS.

What this does for you:

  • Gives you authentication via OAuth-js to our identity server, then sets an access token so that our model layer can interact with our services.
  • Provides a route ("/token") that can accept an access_token query parameter that will also set your access token, skipping OAuth. The idea behind this is that you are likely going to one of these applications from one that already has a valid token.
  • Provides current-user and current-practice-user models, which will get the ME json from Snowflake and provide you with some necessary authentication information.

Installation

npm install --save-dev ember-icis-auth
ember g ember-icis-auth

Then modify your Brocfile.js to add this:

//Brocfile.js
app.import('bower_components/oauth-js/dist/oauth.js');

Create an OAuth initializer:

//app/initializers/oauth.js
import config from 'notes-dash/config/environment';

export default {
  name: 'notes-dash',
  initialize: function() {
    OAuth.initialize(config.APP.OAUTHD_KEY);
    OAuth.setOAuthdURL(config.APP.OAUTHD_URL);
  }
};

Create authenticator service, and optionally a test double service:

//app/services/authenticator.js
import authenticator from 'ember-icis-auth/services/authenticator';
import config from 'notes-dash/config/environment';

export default authenticator.extend({
  snowflake_provider: config.APP.SNOWFLAKE_PROVIDER
});

//app/services/test-authenticator.js
import authenticator from 'ember-icis-auth/services/test-authenticator';
import config from 'notes-dash/config/environment';

export default authenticator.extend({
  snowflake_provider: config.APP.SNOWFLAKE_PROVIDER
});

Create an Authenticator initializer:

//app/initializer/authenticator.js
import config from 'notes-dash/config/environment';

export function initialize(container, application) {
  var service;
  if (config.environment === 'test') {
    // use provided test double in test environment
    service = 'service:test-authenticator';
  } else {
    service = 'service:authenticator';
  }

  // injects dependency into all routes
  application.inject('route', 'authenticator', service);

  // Alternatively you can inject the authenticator into only routes which need
  // to access it, (for example the auth route, routes with include the
  // AuthenticatedRouteMixin, routes with custom auth logic):
  // application.inject('route:some-authenticated-route', 'authenticator', service);
}

export default {
  name: 'authenticator',
  initialize: initialize
};

Set the specific route configs:

//app/routes/index.js
import config from 'notes-dash/config/environment';
import Index from 'ember-icis-auth/routes/index';

export default Index.reopen({
  snowflake_provider: config.APP.SNOWFLAKE_PROVIDER,
  snowflake_url: config.APP.SNOWFLAKE_URI
});

//app/routes/auth.js
import Auth from 'ember-icis-auth/routes/auth'
import config from 'notes-dash/config/environment'

export default Auth.reopen({
  snowflake_provider: config.APP.SNOWFLAKE_PROVIDER
});

Set up the store adapter for the current-user model:

//app/adapters/current-user.js
import CurrentUser from 'ember-icis-auth/adapters/current-user';
import config from 'notes-dash/config/environment';

export default CurrentUser.reopen({
  host: config.APP.SNOWFLAKE_URI
});

And finally setup the basic routing:

//app/router.js
Router.map(function() {
  this.route("auth");
  this.route("token");
});

Transitioning to other routes after auth

The default behavior in the auth route transitions to the app's index after successful authentication. You may wish to implement other logic, and the auth route makes it easy to do so using the transitionToTargetRoute callback.

//app/routes/auth.js
import Auth from 'ember-icis-auth/routes/auth'
import config from 'notes-dash/config/environment'

export default Auth.reopen({
  snowflake_provider: config.APP.SNOWFLAKE_PROVIDER,

  transitionToTargetRoute: function(transition) {
    console.log("We're authenticated now!");
    this._super(transition);
  }
});

Running Tests

  • ember test
  • ember test --server

Local development of addon

It's often easier to provide a local link to this library while developing a widget. This is how you go about it.

In the CLI app you are building first lower the requirement for the widget lib:

//package.json
"devDependencies": {
  //"ember-icis-auth": "~ 0.1.0"
  "ember-icis-auth": "*"
}

Next, in this directory link the local version into npm:

npm link

Then in the CLI directory, link the local version of this lib:

npm link ember-icis-auth