UNPKG

2.11 kBMarkdownView Raw
1# authmaker-ember-simple-auth
2
3## Installation - quick start
4
5Install Ember Simple Auth:
6```
7ember install ember-simple-auth
8```
9
10Install this package:
11```
12ember install authmaker-ember-simple-auth
13```
14
15Add Authmaker config to your environment:
16```
17authmaker: {
18 domainUrl = "http://localhost:5000",
19 redirectUri = "http://localhost:4200/login",
20 clientId = "some client Id"
21},
22```
23
24Add a login route using `ember g route login` and make it use the Authmaker Login Route Mixin:
25```
26import Ember from 'ember';
27import AuthmakerLoginRoute from 'authmaker-ember-simple-auth/mixins/login-route';
28import Config from 'your-app/config/environment';
29
30export default Ember.Route.extend(AuthmakerLoginRoute, {
31 config: Config.authmaker //this is very important, do not forget to add this
32});
33```
34
35## Authmaker Simple Auth Specific Usage
36
37Add `application-route-mixin` to your application route:
38
39```
40import Ember from 'ember';
41import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';
42
43export default Ember.Route.extend(ApplicationRouteMixin, {
44});
45```
46
47To allow your user to login you can use the Ember Simple Auth's `session.authenticate()` as follows:
48
49```
50import Ember from 'ember';
51import Config from 'your-app/config/environment';
52
53export default Ember.Controller.extend({
54 actions: {
55 login() {
56 return this.get('session').authenticate('authenticator:authmaker', Config.authmaker);
57 }
58 }
59});
60```
61
62Authmaker automatically provides an application authorizer which you can use as follows:
63```
64import ApplicationAdapter from './application';
65import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';
66
67export default ApplicationAdapter.extend(DataAdapterMixin, {
68 authorizer: 'authorizer:application',
69});
70```
71
72### General Simple Auth Usage
73If you want to be able to logout using an action such as this `{{action "logout"}}` you just need to call
74
75```
76import Ember from 'ember';
77import Config from 'your-app/config/environment';
78
79export default Ember.Controller.extend({
80 actions: {
81 logout() {
82 this.get('session').invalidate();
83 }
84 }
85});
86```