|
1 | | ---- |
2 | | -title: Configure your app |
3 | | ---- |
| 1 | +After successfully creating your Authmaker instance, it is time to create your |
| 2 | +app and configure it to use your new Authmaker Instance. |
4 | 3 |
|
5 | | -After successfully creating your Authmaker instance, configure your existing Ember application to work with Authmaker. |
| 4 | +## Create your app |
6 | 5 |
|
7 | | -#### Install addons |
8 | | - |
9 | | -Authmaker works with [ember-simple-auth](https://ember-simple-auth.com/) to allow easy implementation of authentication and authorization in your app. From your Ember application directory, install ember-simple-auth and then authmaker-simple-auth: |
| 6 | +The quickest way to create your new application is to use the following npm init command: |
10 | 7 |
|
11 | 8 | ```bash |
12 | | -$ ember install ember-simple-auth |
13 | | -$ ember install authmaker-ember-simple-auth |
| 9 | +npm init ember-app your-amazing-app |
14 | 10 | ``` |
15 | 11 |
|
16 | | -#### Add Authmaker config |
| 12 | +This will create a new application for you in the folder `your-amazing-app`. You can make sure that it has initialised correctly by navigating to that app and starting it: |
17 | 13 |
|
18 | | -Open `config/environment.js` and include the configuration details provided by Authmaker when you created your instance. These will be unique to your project. (Make sure to use the _local_ configuration while in development.) |
| 14 | +```bash |
| 15 | +cd your-amazing-app |
| 16 | +npm start |
| 17 | +``` |
19 | 18 |
|
20 | | -```javascript {data-filename=config/environment.js} |
| 19 | +You should be prompted to visit http://localhost:4200 which should look something like this when you visit it: |
21 | 20 |
|
22 | | -... |
| 21 | + |
23 | 22 |
|
24 | | - if (environment === 'development') { |
25 | | - // this object will be *UNIQUE* for your instance |
26 | | - ENV.authmaker = { |
27 | | - domainUrl: "https://my-app-name.authmaker.com", |
28 | | - redirectUri: "http://localhost:4200/login", |
29 | | - clientId: "yourClientId" |
30 | | - }; |
31 | | - } |
| 23 | +Next we need to install the Authmaker addon. |
32 | 24 |
|
33 | | -... |
34 | | -``` |
| 25 | +## Installing Authmaker Simple Auth |
35 | 26 |
|
36 | | -#### Add ApplicationRouteMixin |
| 27 | +To get you started as quickly as possible we provide an Ember Addon that provides a lot of the functionality you would need. It is built to extend [ember-simple-auth](https://ember-simple-auth.com/) to allow easy implementation of authentication and authorization in your app. |
37 | 28 |
|
38 | | -Generate an application route if you do not already have one: |
| 29 | +From your Ember application directory, install [authmaker-ember-simple-auth](https://github.com/Authmaker/authmaker-ember-simple-auth) as follows: |
39 | 30 |
|
40 | 31 | ```bash |
41 | | -$ ember g route application |
| 32 | +ember install authmaker-ember-simple-auth |
42 | 33 | ``` |
43 | 34 |
|
44 | | -Include the `ApplicationRouteMixin` that ember-simple-auth provides, as shown below: |
45 | | - |
46 | | -```javascript {data-filename=app/routes/application.js} |
| 35 | +This will create a bunch of files in your application for you and update your environment config with example config that you will need to update before the Addon will start working. |
47 | 36 |
|
48 | | -import Ember from 'ember'; |
49 | | -import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin'; |
| 37 | +### Update Authmaker config |
50 | 38 |
|
51 | | -export default Ember.Route.extend(ApplicationRouteMixin, { |
52 | | -}); |
53 | | -``` |
54 | | - |
55 | | -#### Add DataAdapterMixin |
| 39 | +If you open `config/environment.js` you will see that there are sections that will look something like this: |
56 | 40 |
|
57 | | -Next, generate an application adapter if you do not already have one: |
58 | 41 |
|
59 | | -```bash |
60 | | -$ ember g adapter application |
| 42 | +```javascript {data-filename=config/environment.js} |
| 43 | +if (environment === 'development') { |
| 44 | + ENV.authmaker = { |
| 45 | + domainUrl: 'REPLACE_ME', |
| 46 | + redirectUri: 'REPLACE_ME', |
| 47 | + clientId: 'REPLACE_ME' |
| 48 | + }; |
| 49 | +} |
61 | 50 | ``` |
62 | 51 |
|
63 | | -In order to automatically include authorization headers on all outgoing requests to the server, we need to include the `DataAdapterMixin` provided by ember-simple-auth in our application adapter. Add the following to `app/adapters/application.js`: |
64 | | - |
65 | | -```javascript {data-filename=app/adapters/application.js} |
| 52 | +You will need to replace these example configurations with the real config for your Authmaker application. To get the real configuration you should [login to your Authmaker dashboard](https://app.authmaker.com/instances) and click the button marked "Local Ember Config": |
66 | 53 |
|
67 | | -import DS from 'ember-data'; |
68 | | -import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin'; |
| 54 | + |
69 | 55 |
|
70 | | -export default DS.JSONAPIAdapter.extend(DataAdapterMixin, { |
71 | | - authorizer: 'authorizer:application', |
72 | | -}); |
73 | | -``` |
| 56 | +When you click the button there will be a pop up with your specific config for your Authmaker app and you should replace the example config in the `development` section of your `environment.js` file to reflect this specific config. |
0 commit comments