Skip to content

Commit 2445721

Browse files
authored
Merge pull request #1 from neroniaky/master
Update to current version
2 parents aafb0f7 + 69be778 commit 2445721

13 files changed

+270
-123
lines changed

.npmignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
src
21
node_modules
32

43
# Testing

CHANGELOG.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
11
# Change Log
22

3-
## v0.1.4
3+
## v0.1.8 & v0.1.9
4+
**Features:**
5+
- Updated Dependencies to Angular2 Final
6+
7+
## v0.1.7
8+
**Features:**
9+
- Added .head() and .options() HTTP-wrapper
10+
- Added general HTTP-wrapper .sendHttpRequest()
11+
12+
## v0.1.6
413
**Bugfixes:**
14+
- Added route guard support for CanActivate
15+
16+
## v0.1.5
17+
**Bugfixes:**
18+
- Fix broken sourcemap paths in npm package
19+
20+
## v0.1.4
21+
**Features:**
522
- Added packaged library to npm package for systemjs support (fixes [#6](https://github.com/neroniaky/angular2-token/issues/6))
23+
- Update Dependencies to Angular2 RC6
624

725
## v0.1.3
826
**Bugfixes:**

README.md

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
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
3742
1. Install Angular2-Token via NPM with
3843
```bash
39-
npm install angular2-token --save
44+
npm install angular2-token
4045
```
4146

4247
2. 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
113119
Further 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
241264
An array of `UserType` can be passed in `Angular2TokenOptions` during `init()`.
242265
The user type is selected during sign in and persists until sign out.
@@ -260,13 +283,40 @@ this._tokenService.signIn(
260283
this._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
265306
npm 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
269319
Test 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)

angular2-token.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export * from './lib';
1+
export * from './src/angular2-token.model';
2+
export * from './src/angular2-token.service';

angular2-token.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
exports.Angular2TokenService = require('./lib/angular2-token.service').Angular2TokenService;
1+
"use strict";
2+
function __export(m) {
3+
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4+
}
5+
__export(require('./lib/angular2-token.service'));

assets/angular2-token-logo.png

128 KB
Loading

config/spec-bundle.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@ require('ts-helpers');
88

99
require('zone.js/dist/zone');
1010
require('zone.js/dist/long-stack-trace-zone');
11-
require('zone.js/dist/jasmine-patch');
11+
require('zone.js/dist/proxy'); // since zone.js 0.6.15
12+
require('zone.js/dist/sync-test');
13+
require('zone.js/dist/jasmine-patch'); // put here since zone.js 0.6.14
1214
require('zone.js/dist/async-test');
1315
require('zone.js/dist/fake-async-test');
14-
require('zone.js/dist/sync-test');
1516

1617
// RxJS
1718
require('rxjs/Rx');
1819

1920
var testing = require('@angular/core/testing');
2021
var browser = require('@angular/platform-browser-dynamic/testing');
2122

22-
testing.setBaseTestProviders(
23-
browser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
24-
browser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS
23+
testing.TestBed.initTestEnvironment(
24+
browser.BrowserDynamicTestingModule,
25+
browser.platformBrowserDynamicTesting()
2526
);
2627

2728
var testContext = require.context('../src', true, /\.spec\.ts/);

package.json

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular2-token",
3-
"version": "0.1.4",
3+
"version": "0.1.9",
44
"description": "Angular2 service for token based authentication",
55
"main": "./angular2-token.js",
66
"typings": "./angular2-token.d.ts",
@@ -14,55 +14,57 @@
1414
"token authentication"
1515
],
1616
"peerDependencies": {
17-
"@angular/core": "2.0.0-rc.5",
18-
"@angular/http": "2.0.0-rc.5",
19-
"@angular/common": "2.0.0-rc.5",
20-
"@angular/router": "^3.0.0-rc.1",
21-
"rxjs": "5.0.0-beta.6"
17+
"@angular/core": "2.0.0",
18+
"@angular/http": "2.0.0",
19+
"@angular/common": "2.0.0",
20+
"@angular/router": "3.0.0",
21+
"rxjs": "5.0.0-beta.12"
2222
},
2323
"devDependencies": {
24-
"@angular/common": "2.0.0-rc.5",
25-
"@angular/compiler": "2.0.0-rc.5",
26-
"@angular/core": "2.0.0-rc.5",
27-
"@angular/http": "2.0.0-rc.5",
28-
"@angular/router": "^3.0.0-rc.1",
29-
"@angular/platform-browser": "2.0.0-rc.5",
30-
"@angular/platform-browser-dynamic": "2.0.0-rc.5",
31-
"@angular/platform-server": "2.0.0-rc.5",
24+
25+
"@angular/core": "2.0.0",
26+
"@angular/http": "2.0.0",
27+
"@angular/common": "2.0.0",
28+
"@angular/router": "3.0.0",
29+
"rxjs": "5.0.0-beta.12",
30+
31+
"@angular/compiler": "2.0.0",
32+
"@angular/platform-browser": "2.0.0",
33+
"@angular/platform-browser-dynamic": "2.0.0",
34+
"@angular/platform-server": "2.0.0",
3235
"ie-shim": "^0.1.0",
33-
"rxjs": "5.0.0-beta.6",
34-
"typescript": "^2.0.0-beta",
35-
"zone.js": "0.6.13",
36+
"typescript": "^2.0.0",
37+
"zone.js": "0.6.23",
3638

3739
"@types/core-js": "^0.9.28",
3840
"@types/hammerjs": "^2.0.28",
3941
"@types/jasmine": "^2.2.29",
40-
"@types/node": "^4.0.29",
42+
"@types/node": "^6.0.38",
4143
"@types/source-map": "^0.1.26",
4244
"@types/webpack": "^1.12.29",
4345
"@types/protractor": "^1.5.16",
4446

45-
"awesome-typescript-loader": "1.1.1",
47+
"awesome-typescript-loader": "^2.2.1",
4648
"source-map-loader": "^0.1.5",
47-
"istanbul-instrumenter-loader": "^0.2.0",
49+
"istanbul-instrumenter-loader": "^1.0.0",
4850

49-
"protractor": "^3.2.2",
51+
"protractor": "4.0.7",
5052

51-
"core-js": "^2.4.0",
53+
"core-js": "^2.4.1",
5254
"http-server": "^0.9.0",
5355

5456
"jasmine-core": "^2.4.1",
55-
"karma": "^0.13.22",
56-
"karma-chrome-launcher": "^1.0.1",
57+
"karma": "1.3.0",
58+
"karma-chrome-launcher": "^2.0.0",
5759
"karma-coverage": "^1.0.0",
5860
"karma-jasmine": "^1.0.2",
5961
"karma-mocha-reporter": "^2.0.0",
6062
"karma-sourcemap-loader": "^0.3.7",
61-
"karma-webpack": "1.7.0",
63+
"karma-webpack": "1.8.0",
6264
"remap-istanbul": "^0.6.3",
6365

6466
"ts-helpers": "1.1.1",
65-
"ts-node": "^0.9.1",
67+
"ts-node": "1.3.0",
6668
"webpack": "^1.13.1"
6769
},
6870
"author": "Jan-Philipp Riethmacher <neroniaky@gmail.com>",

src/angular2-token.model.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import {
2+
RequestMethod,
3+
RequestOptions
4+
} from '@angular/http';
5+
16
export interface UserType {
27
name: string;
38
path: string;
@@ -11,20 +16,33 @@ export interface AuthData {
1116
uid: string;
1217
}
1318

19+
export interface OAuthPaths {
20+
github?: string;
21+
}
22+
1423
export interface Angular2TokenOptions {
15-
apiPath?: string;
16-
signInPath?: string;
17-
signOutPath?: string;
18-
validateTokenPath?: string;
24+
apiPath?: string;
25+
signInPath?: string;
26+
signOutPath?: string;
27+
validateTokenPath?: string;
1928

20-
deleteAccountPath?: string;
21-
registerAccountPath?: string;
22-
registerAccountCallback?: string;
29+
deleteAccountPath?: string;
30+
registerAccountPath?: string;
31+
registerAccountCallback?: string;
2332

24-
updatePasswordPath?: string;
33+
updatePasswordPath?: string;
2534

26-
resetPasswordPath?: string;
27-
resetPasswordCallback?: string;
35+
resetPasswordPath?: string;
36+
resetPasswordCallback?: string;
2837

29-
userTypes?: UserType[];
38+
userTypes?: UserType[];
39+
40+
oAuthPaths?: OAuthPaths;
3041
}
42+
43+
export interface HttpRequestOptions {
44+
requestMethod: RequestMethod,
45+
path: string,
46+
body?: any,
47+
requestOptions?: RequestOptions
48+
}

0 commit comments

Comments
 (0)