|
@@ -153,7 +153,7 @@ public class BeerController {
|
153
|
153
|
|
154
|
154
|
Access the API using `http localhost:8080/good-beers --auth <user>:<password>`.
|
155
|
155
|
|
156
|
|
-## Ionic App
|
|
156
|
+## Create Ionic App
|
157
|
157
|
|
158
|
158
|
Install Ionic and Cordova: `yarn global add cordova ionic`
|
159
|
159
|
|
|
@@ -174,24 +174,43 @@ This will open your default browser on [http://localhost:8100](http://localhost:
|
174
|
174
|
|
175
|
175
|
Thanks to the [recent release of Stormpath's Client API](https://stormpath.com/blog/client-api-authentication-mobile-frontend), you can now authenticate directly without needing to hit your server with a Stormpath SDK integration installed. This article shows you how to do just that in an Ionic application.
|
176
|
176
|
|
177
|
|
-Install the [Angular components for Stormpath](https://github.com/stormpath/stormpath-sdk-angular):
|
|
177
|
+## Upgrade to Angular 2.3
|
178
|
178
|
|
179
|
|
-```
|
180
|
|
-yarn add angular-stormpath
|
|
179
|
+With Angular versions less than 2.3, you can’t extend components and override their templates. The Ionic pages for Stormpath module uses component extension to override the templates in its pages. Because of this, you have to upgrade your project to use Angular 2.3. The only downside to use Angular 2.3 with Ionic 2.0.0 is that you won’t be able to use the `--prod` build flag when compiling. This is because its compiler does not support Angular 2.3.
|
|
180
|
+
|
|
181
|
+To begin, modify `package.json` so all the `angular` dependencies use version `2.3.1` rather than `2.2.1`.
|
|
182
|
+
|
|
183
|
+```json
|
|
184
|
+"dependencies": {
|
|
185
|
+ "@angular/common": "2.3.1",
|
|
186
|
+ "@angular/compiler": "2.3.1",
|
|
187
|
+ "@angular/compiler-cli": "2.3.1",
|
|
188
|
+ "@angular/core": "2.3.1",
|
|
189
|
+ "@angular/forms": "2.3.1",
|
|
190
|
+ "@angular/http": "2.3.1",
|
|
191
|
+ "@angular/platform-browser": "2.3.1",
|
|
192
|
+ "@angular/platform-browser-dynamic": "2.3.1",
|
|
193
|
+ "@angular/platform-server": "2.3.1",
|
|
194
|
+ ...
|
181
|
195
|
```
|
182
|
196
|
|
183
|
|
-Modify `app.module.ts` to import the appropriate Stormpath classes from `angular-stormpath`. Create a function to configure the `endpointPrefix` to point to the DNS label for your Client API instance.
|
|
197
|
+Run `npm install` to update to these versions.
|
184
|
198
|
|
185
|
|
-**NOTE:** You can find and configure your DNS label by logging into https://api.stormpath.com and navigating to Applications > My Application > Policies > Client API > DNS Label. Since mine is “raible”, I’ll be using `raible.apps.stormpath.io` for this example.
|
|
199
|
+## Install Ionic Pages for Stormpath
|
186
|
200
|
|
187
|
|
-Make sure to define `stormpathConfig`, override the provider, import `StormpathModule` / `StormpathIonicModule`, and append Stormpath's pre-built Ionic pages to `entryComponents`.
|
|
201
|
+Install [Ionic pages for Stormpath](https://github.com/stormpath/stormpath-sdk-angular-ionic):
|
188
|
202
|
|
|
203
|
+```
|
|
204
|
+yarn add angular-stormpath-ionic
|
|
205
|
+```
|
|
206
|
+
|
|
207
|
+Modify `src/app/app.module.ts` to define a `stormpathConfig` function. This function is used to configure the `endpointPrefix` to point to the DNS label for your Client API instance. Import `StormpathModule`, `StormpathIonicModule`, and override the instance of `StormpathConfiguration`. You’ll also need to append Stormpath's pre-built Ionic pages to `entryComponents`.
|
|
208
|
+
|
|
209
|
+**NOTE:** You can find and configure your DNS label by logging into https://api.stormpath.com and navigating to Applications > My Application > Policies > Client API > DNS Label. Since mine is “raible”, I’ll be using `raible.apps.stormpath.io` for this example.
|
189
|
210
|
|
190
|
211
|
```typescript
|
191
|
|
-import {
|
192
|
|
- StormpathConfiguration, StormpathModule, StormpathIonicModule,
|
193
|
|
- LoginPage, RegisterPage, ForgotPasswordPage
|
194
|
|
-} from 'angular-stormpath';
|
|
212
|
+import { StormpathConfiguration, StormpathModule } from 'angular-stormpath';
|
|
213
|
+import { StormpathIonicModule, LoginPage, ForgotPasswordPage, RegisterPage } from 'angular-stormpath-ionic';
|
195
|
214
|
|
196
|
215
|
export function stormpathConfig(): StormpathConfiguration {
|
197
|
216
|
let spConfig: StormpathConfiguration = new StormpathConfiguration();
|
|
@@ -221,14 +240,15 @@ export function stormpathConfig(): StormpathConfiguration {
|
221
|
240
|
export class AppModule {}
|
222
|
241
|
```
|
223
|
242
|
|
224
|
|
-To render a login page before users can view the application, you can modify `src/app/app.component.ts` to use the `Stormpath` service and navigate to Stormpath's `LoginPage` if the user is not authenticated.
|
|
243
|
+To render a login page before users can view the application, modify `src/app/app.component.ts` to use the `Stormpath` service and navigate to Stormpath's `LoginPage` if the user is not authenticated.
|
225
|
244
|
|
226
|
245
|
```typescript
|
227
|
246
|
import { Component } from '@angular/core';
|
228
|
247
|
import { Platform } from 'ionic-angular';
|
229
|
248
|
import { StatusBar, Splashscreen } from 'ionic-native';
|
230
|
249
|
import { TabsPage } from '../pages/tabs/tabs';
|
231
|
|
-import { Stormpath, LoginPage } from 'angular-stormpath';
|
|
250
|
+import { Stormpath } from 'angular-stormpath';
|
|
251
|
+import { LoginPage } from 'angular-stormpath-ionic';
|
232
|
252
|
|
233
|
253
|
@Component({
|
234
|
254
|
templateUrl: 'app.html'
|