1+ ![ Angular2-Token] ( assets/angular2-token-logo.png )
2+
13# Angular2-Token
24[ ![ Join the chat at https://gitter.im/lynndylanhurley/devise_token_auth ] ( https://badges.gitter.im/Join%20Chat.svg )] ( https://gitter.im/angular2-token/Lobby )
35[ ![ npm version] ( https://badge.fury.io/js/angular2-token.svg )] ( https://badge.fury.io/js/angular2-token )
@@ -28,15 +30,18 @@ The repository can be found [here](https://github.com/neroniaky/angular2-token-e
2830 - [ ` .updatePassword() ` ] ( #updatepassword )
2931 - [ ` .resetPassword() ` ] ( #resetpassword )
3032- [ HTTP Service Wrapper] ( #http-service-wrapper )
33+ - [ ` .sendHttpRequest() ` ] ( #sendhttprequest )
3134- [ Multiple User Types] ( #multiple-user-types )
35+ - [ Route Guards] ( #route-guards )
3236- [ Testing] ( #testing )
37+ - [ Development] ( #development )
3338- [ Credits] ( #credits )
3439- [ License] ( #license )
3540
3641## Installation
37421 . Install Angular2-Token via NPM with
3843 ``` bash
39- npm install angular2-token --save
44+ npm install angular2-token
4045 ```
4146
42472. Import and add ` Angular2TokenService` to your main module. ` Angular2TokenService` depends on ` HttpModule` and ` RouterModule` , so make sure you imported them too.
@@ -97,18 +102,19 @@ constructor(private _tokenService: Angular2TokenService) {
97102}
98103` ` `
99104
100- # ## Configuration Options
101- - ` apiPath? : string` - Sets base path all operations are based on
102- - ` signInPath? : string` - Sets path for sign in
103- - ` signOutPath? : string` - Sets path for sign out
104- - ` validateTokenPath? : string` - Sets path for token validation
105- - ` registerAccountPath? : string` - Sets path for account registration
106- - ` deleteAccountPath? : string` - Sets path for account deletion
107- - ` registerAccountCallback? : string` - Sets the path user are redirected to after email confirmation for registration
108- - ` updatePasswordPath? : string` - Sets path for password update
109- - ` resetPasswordPath? : string` - Sets path for password reset
110- - ` resetPasswordCallback? : string` - Sets the path user are redirected to after email confirmation for password reset
111- - ` userTypes? : UserTypes[]` - Allows the configuration of multiple user types (see [Multiple User Types](# multiple-user-types))
105+ | Options | Description |
106+ | ----------------------------------- | ----------------------------------------------- |
107+ | ` apiPath? : string` | Sets base path all operations are based on |
108+ | ` signInPath? : string` | Sets path for sign in |
109+ | ` signOutPath? : string` | Sets path for sign out |
110+ | ` validateTokenPath? : string` | Sets path for token validation |
111+ | ` registerAccountPath? : string` | Sets path for account registration |
112+ | ` deleteAccountPath? : string` | Sets path for account deletion |
113+ | ` registerAccountCallback? : string` | Sets the path user are redirected to after email confirmation for registration |
114+ | ` updatePasswordPath? : string` | Sets path for password update |
115+ | ` resetPasswordPath? : string` | Sets path for password reset |
116+ | ` resetPasswordCallback? : string` | Sets the path user are redirected to after email confirmation for password reset |
117+ | ` userTypes? : UserTypes[]` | Allows the configuration of multiple user types (see [Multiple User Types](# multiple-user-types)) |
112118
113119Further information on paths/routes can be found at
114120[devise token auth](https://github.com/lynndylanhurley/devise_token_auth#usage-tldr)
@@ -222,12 +228,14 @@ this._tokenService.updatePassword(
222228` ` `
223229
224230# # HTTP Service Wrapper
225- ` Angular2TokenService` wraps all standard Angular2 Http Service calls for authentication and token processing.
231+ ` Angular2TokenService` wraps all standard Angular2 Http Service calls for authentication and token processing.
226232- ` get(path: string, requestOptions? : RequestOptions): Observable< Response> `
227233- ` post(path: string, data: any, requestOptions? : RequestOptions): Observable< Response> `
228234- ` put(path: string, data: any, requestOptions? : RequestOptions): Observable< Response> `
229235- ` delete(path: string, requestOptions? : RequestOptions): Observable< Response> `
230236- ` patch(path: string, data: any, requestOptions? : RequestOptions): Observable< Response> `
237+ - ` head(path: string, requestOptions? : RequestOptions): Observable< Response> `
238+ - ` options(path: string, requestOptions? : RequestOptions): Observable< Response> `
231239
232240# ### Example:
233241` ` ` javascript
@@ -237,6 +245,21 @@ this._tokenService.get('my-resource/1').map(res => res.json()).subscribe(
237245);
238246` ` `
239247
248+ # ## .sendHttpRequest()
249+ More customized requests can be send with the ` .sendHttpRequest()` -function. It is used by all Http wrappers.
250+
251+ ` sendHttpRequest(options: HttpRequestOptions): Observable< Response> `
252+
253+ # ### Example:
254+ ` ` ` javascript
255+ this.sendHttpRequest({
256+ requestMethod: RequestMethod.Post,
257+ path: ' my-resource/1' ,
258+ data: mydata
259+ requestOptions: myRequestOptions
260+ });
261+ ` ` `
262+
240263# # Multiple User Types
241264An array of ` UserType` can be passed in ` Angular2TokenOptions` during ` init()` .
242265The user type is selected during sign in and persists until sign out.
@@ -260,13 +283,40 @@ this._tokenService.signIn(
260283this._tokenService.currentUser; // ADMIN
261284` ` `
262285
286+ # # Route Guards
287+ Angular2-Token implements the ` CanActivate` interface, so it can directly be used
288+ as a route guard. It currently does not distinguish between user types.
289+
290+ # ### Example:
291+ ` ` ` javascript
292+ const routerConfig: Routes = [
293+ {
294+ path: ' ' ,
295+ component: PublicComponent
296+ }, {
297+ path: ' restricted' ,
298+ component: RestrictedComponent,
299+ canActivate: [Angular2TokenService]
300+ }
301+ ];
302+ ` ` `
303+
263304# # Testing
264305` ` ` bash
265306npm test
266307` ` `
267308
309+ # # Development
310+ If the package is installed from Github specified in the package.json, you need to build the package locally.
311+
312+ ` ` ` bash
313+ cd ./node_modules/angular2-token
314+ npm install
315+ npm run build
316+ ` ` `
317+
268318# # Credits
269319Test config files based on [Angular2 Webpack Starter](https://github.com/AngularClass/angular2-webpack-starter) by AngularClass
270320
271321# # License
272- The MIT License (see the [LICENSE](https://github.com/neroniaky/angular2-token/blob/master/LICENSE) file for the full text)
322+ The MIT License (see the [LICENSE](https://github.com/neroniaky/angular2-token/blob/master/LICENSE) file for the full text)
0 commit comments