Pārlūkot izejas kodu

Add autoAuthorizedUris

Matt Raible 7 gadus atpakaļ
vecāks
revīzija
7624809f08
1 mainītis faili ar 14 papildinājumiem un 2 dzēšanām
  1. 14
    2
      TUTORIAL.md

+ 14
- 2
TUTORIAL.md Parādīt failu

@@ -361,7 +361,7 @@ Change `src/providers/beer-service.ts` to use have a `getGoodBeers()` method.
361 361
 
362 362
 ```typescript
363 363
 import { Injectable } from '@angular/core';
364
-import { Http, Response } from '@angular/http';
364
+import { Http, Response, RequestOptions } from '@angular/http';
365 365
 import 'rxjs/add/operator/map';
366 366
 import { Observable } from 'rxjs';
367 367
 import { StormpathConfiguration } from 'angular-stormpath';
@@ -377,12 +377,24 @@ export class BeerService {
377 377
   }
378 378
 
379 379
   getGoodBeers(): Observable<any> {
380
-    return this.http.get(this.API + '/good-beers')
380
+    let options = new RequestOptions({ withCredentials: true });
381
+    return this.http.get(this.API + '/good-beers', options)
381 382
       .map((response: Response) => response.json());
382 383
   }
383 384
 }
384 385
 ```
385 386
 
387
+**TIP:** If you don’t want to pass in `withCredentials: true`, you can add the API URI as an `autoAuthorizeUri` in `StormpathConfiguration`.
388
+
389
+```typescript
390
+export function stormpathConfig(): StormpathConfiguration {
391
+  let spConfig: StormpathConfiguration = new StormpathConfiguration();
392
+  spConfig.endpointPrefix = 'http://localhost:8080';
393
+  spConfig.autoAuthorizedUris.push(new RegExp('http://localhost:8080/good-beers'));
394
+  return spConfig;
395
+}
396
+```
397
+
386 398
 Modify `beer.html` to show the list of beers.
387 399
 
388 400
 ```html