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-authember g ember-icis-auth
Then modify your Brocfile.js to add this:
//Brocfile.jsapp;
Create an OAuth initializer:
//app/initializers/oauth.js; name: 'notes-dash' { OAuth; OAuth; };
Create authenticator service, and optionally a test double service:
//app/services/authenticator.js;; ; //app/services/test-authenticator.js;; ;
Create an Authenticator initializer:
//app/initializer/authenticator.js; { var service; if configenvironment === 'test' // use provided test double in test environment service = 'service:test-authenticator'; else service = 'service:authenticator'; // injects dependency into all routes application; // 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);} name: 'authenticator' initialize: initialize;
Set the specific route configs:
//app/routes/index.js;; ; //app/routes/auth.js ;
Set up the store adapter for the current-user model:
//app/adapters/current-user.js;; ;
And finally setup the basic routing:
//app/router.jsRouter;
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 ;
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