Skip to content

Commit 829aece

Browse files
author
Anthony Kirwan
committed
update to 2.0.3
1 parent c532e3a commit 829aece

File tree

7 files changed

+50
-53
lines changed

7 files changed

+50
-53
lines changed

CHANGELOG.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
# Changelog Ember-OAuth2
22

3+
## v2.0.3-beta
4+
(Full Changelog)[https://github.com/amkirwan/ember-oauth2/compare/v2.0.2-beta...v2.0.3-beta]
5+
- fix typo in scope
6+
37
## v2.0.2-beta
4-
(Full Changelog)[https://github.com/amkirwan/ember-oauth2/compare/v2.0.1-beta...v2.0.2-beta]
8+
(Full Changelog)[https://github.com/amkirwan/ember-oauth2/compare/v2.0.1-beta...v2.0.2-beta]
59

6-
- add setProvider method
10+
- add setProvider method
711
- change init to not take providerId
812

913
## v2.0.1-beta
10-
(Full Changelog)[https://github.com/amkirwan/ember-oauth2/compare/v2.0.0-beta...v2.0.1-beta]
14+
(Full Changelog)[https://github.com/amkirwan/ember-oauth2/compare/v2.0.0-beta...v2.0.1-beta]
1115

12-
- Update NPM author info
16+
- Update NPM author info
1317

1418
## v2.0.0-beta
15-
(Full Changelog)[https://github.com/amkirwan/ember-oauth2/compare/v1.1.0...v2.0.0-beta]
19+
(Full Changelog)[https://github.com/amkirwan/ember-oauth2/compare/v1.1.0...v2.0.0-beta]
1620

17-
- Converted to EmberAddon and turned EmberOAuth2 into a service
21+
- Converted to EmberAddon and turned EmberOAuth2 into a service
1822
- Updated testing to use Ember-Qunit
1923
- Update project README
2024

2125
## v1.1.0
2226
- Add verifyToken method to handle mitigation of the confused deputy
23-
- fix bug with checking of state
27+
- fix bug with checking of state
2428

2529
## v1.0.1
2630
- Update getState function to not take a param argument and use the configure statePrefix to find the state from localStorage.
@@ -50,7 +54,7 @@
5054
## v0.5.2
5155
- Update Ember dependeny to 1.7
5256
- Moved bower install dependences from vendor to bower_components
53-
- Add dist dir to repo for bower installs
57+
- Add dist dir to repo for bower installs
5458
## v0.5.1
5559
- Fixed bug where the random UUID for the state was not being set.
5660
- openWindow resolves with a reference to the dialog window and rejects
@@ -65,7 +69,7 @@
6569
- Login dialog window returns a promise, it resolves on success and reject on error
6670
## v0.3.2
6771
- Remove files not needed in package.
68-
- Add build files to dist dir for package manaagers.
72+
- Add build files to dist dir for package manaagers.
6973
## v0.3.1
7074
- Initial relase to Bower
7175
## v0.3.0

README.md

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ JavaScript library for using OAuth 2.0 Implicit Grant flow (Client-Side Flow) or
88

99
This creates an OAuth 2.0 Ember object class for handling authentication with OAuth 2.0 providers.
1010

11-
Current Version: **[2.0.2-beta](https://github.com/amkirwan/ember-oauth2/releases/tag/v2.0.2-beta)**
11+
Current Version: **[2.0.3-beta](https://github.com/amkirwan/ember-oauth2/releases/tag/v2.0.3-beta)**
1212

13-
The EmberCli addon [EmberTokenAuth](https://github.com/amkirwan/ember-token-auth) demonstrates how to use Ember-OAuth2 library for authentication.
13+
The EmberCli addon [EmberTokenAuth](https://github.com/amkirwan/ember-token-auth) demonstrates how to use Ember-OAuth2 library for authentication.
1414

1515
## Dependencies
1616

@@ -21,15 +21,15 @@ Ember-OAuth2 requires Ember and jQuery.
2121

2222
Ember-OAuth2 uses localStorage for saving the tokens, localStorage is supported in Firefox 3.5+, Safari 4+, IE9+, and Chrome.
2323

24-
The latest version of Ember-OAuth2 is an Ember Addon and uses the ES6 modules. This allows Ember-OAuth2 to be used in projects like [EmberCLI](https://github.com/stefanpenner/ember-cli) easier.
24+
The latest version of Ember-OAuth2 is an Ember Addon and uses the ES6 modules. This allows Ember-OAuth2 to be used in projects like [EmberCLI](https://github.com/stefanpenner/ember-cli) easier.
2525

2626

2727
## Installation
2828

2929
Ember-OAuth2 is an Ember Addon that can be installed with the following command from your ember project.
3030

3131
```javascript
32-
$ ember install ember-oauth2
32+
$ ember install ember-oauth2
3333
```
3434

3535
Ember-OAuth2 is an Ember [service](https://guides.emberjs.com/v2.8.0/applications/services/) that you can inject to different parts of your app using the inject syntax
@@ -109,7 +109,7 @@ The following are the options available for configuring a provider:
109109

110110
## Authorization
111111

112-
To sign into the OAuth2 provider create by injecting the service, set the provider with `setProvider` and call the `authorize`. You can inject this addon into your route for example and when the user clicks a button fire the action to handle the request and set the service providerId and call authorize. This is a simple example and you would probably want to wrap this functionality in a session model. Checkout [ember-token-auth](https://github.com/amkirwan/ember-token-auth) for a full example.
112+
To sign into the OAuth2 provider create by injecting the service, set the provider with `setProvider` and call the `authorize`. You can inject this addon into your route for example and when the user clicks a button fire the action to handle the request and set the service providerId and call authorize. This is a simple example and you would probably want to wrap this functionality in a session model. Checkout [ember-token-auth](https://github.com/amkirwan/ember-token-auth) for a full example.
113113

114114
```javascript
115115
// login route
@@ -162,7 +162,7 @@ The `authorize` call returns a `Ember.RSVP.Promise`. Authorize will `resolve` wi
162162

163163
})
164164

165-
When using the client-side flow it is vital to validate the token received from the endpoint, failure to do so will make your application vulnerable to the [confused deputy problem](https://en.wikipedia.org/wiki/Confused_deputy_problem). As of version `v1.0.2` Ember-OAuth2 supports the `verifyToken` method for validating tokens when using the client-side flow. The user will need to override this method for validating the different server endpoints.
165+
When using the client-side flow it is vital to validate the token received from the endpoint, failure to do so will make your application vulnerable to the [confused deputy problem](https://en.wikipedia.org/wiki/Confused_deputy_problem). As of version `v1.0.2` Ember-OAuth2 supports the `verifyToken` method for validating tokens when using the client-side flow. The user will need to override this method for validating the different server endpoints.
166166

167167
Here is an example of how this might be accomplished in an Ember-CLI instance initializer using the Google token validation endpoint.
168168

@@ -178,7 +178,7 @@ export function initialize(app) {
178178
function verifyTokenInit(app) {
179179
EmberOAuth2.reopen({
180180
// mitigate confused deputy
181-
verifyToken: function() {
181+
verifyToken: function() {
182182
return new Ember.RSVP.Promise((resolve, reject) => {
183183
// implement the adapter with the url to the google tokeinfo endpoint
184184
var adapter = app.lookup('adapter:session');
@@ -196,7 +196,7 @@ function verifyTokenInit(app) {
196196
});
197197
}
198198

199-
export default {
199+
export default {
200200
name: 'ember-oauth2',
201201
initialize: initialize
202202
};
@@ -210,7 +210,7 @@ export default {
210210

211211
If using the Authorization Grant flow with your provider your backend server will need to handle the final steps of authorizing your application. Your success handler will need to send the `AUTHORIZATON_CODE` returned from OAuth2 provider to your backend server which can then retrieve an access token using the client_id, client_secret, and authorization_code.
212212

213-
To enable the Authorization Grant flow for a provider set the `responseType` value to `code`.
213+
To enable the Authorization Grant flow for a provider set the `responseType` value to `code`.
214214

215215
```javascript
216216
window.ENV = window.ENV || {};
@@ -224,7 +224,7 @@ window.ENV['ember-oauth2'] = {
224224
}
225225
```
226226

227-
To build Ember.Oauth2 on your system you will need to have [Node.js](http://nodejs.org), and [npm](https://npmjs.org) installed.
227+
To build Ember.Oauth2 on your system you will need to have [Node.js](http://nodejs.org), and [npm](https://npmjs.org) installed.
228228

229229
```bash
230230
$ git clone https://github.com/amkirwan/ember-oauth2
@@ -238,7 +238,7 @@ $ bower install
238238
To run the tests you can run one of the following commands.
239239

240240
```bash
241-
$ ember test
241+
$ ember test
242242
$ ember test --serve
243243
$ npm test
244244
```
@@ -264,7 +264,3 @@ $ yuidoc .
264264
#### Thanks to the following projects for ideas on how to make this work.
265265

266266
* [backbone-oauth](http://github.com/ptnplanet/backbone-oauth)
267-
268-
269-
270-

addon/services/ember-oauth2.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import Ember from 'ember';
44
* @overview OAuth2 addon for Emberjs that stores tokens in the browsers localStorage
55
* @license Licensed under MIT license
66
* See https://raw.github.com/amkirwan/ember-oauth2/master/LICENSE
7-
* @version 2.0.2-beta
7+
* @version 2.0.3-beta
88
*
99
* @module ember-oauth2
1010
* @class ember-oauth2
1111
*/
1212
export default Ember.Service.extend(Ember.Evented, {
13-
VERSION: '2.0.2-beta',
13+
VERSION: '2.0.3-beta',
1414
/**
1515
* initialize with the providerId to find in
1616
* EmberENV['ember-oauth2'] config
@@ -74,8 +74,8 @@ export default Ember.Service.extend(Ember.Evented, {
7474
let dialog = window.open(url, 'Authorize', 'height=600, width=450');
7575
if (window.focus && dialog) { dialog.focus(); }
7676
return new Ember.RSVP.Promise(function(resolve, reject) {
77-
if (dialog) { resolve(dialog); }
78-
else { reject(new Error('Opening dialog login window failed.')); }
77+
if (dialog) { resolve(dialog); }
78+
else { reject(new Error('Opening dialog login window failed.')); }
7979
});
8080
},
8181

@@ -84,7 +84,7 @@ export default Ember.Service.extend(Ember.Evented, {
8484
* Check if the token returned is valid and if so trigger `success` event else trigger `error`
8585
*
8686
* @method handleRedirect
87-
* @param {Object} hash The window location hash callback url
87+
* @param {Object} hash The window location hash callback url
8888
* @param {Function} callback Optional callback
8989
*/
9090

@@ -95,12 +95,12 @@ export default Ember.Service.extend(Ember.Evented, {
9595
if (self.authSuccess(params) && self.checkState(params.state)) {
9696
if (self.get('responseType') === 'token') {
9797
self.saveToken(self.generateToken(params));
98-
// verify the token on the client end
98+
// verify the token on the client end
9999
self.verifyToken().then(function(result) {
100-
/*jshint unused:false*/
100+
/*jshint unused:false*/
101101
self.trigger('success');
102102
}, function(error) {
103-
/*jshint unused:false*/
103+
/*jshint unused:false*/
104104
self.removeToken();
105105
self.trigger('error', 'Error: verifying token', params);
106106
});
@@ -181,8 +181,6 @@ export default Ember.Service.extend(Ember.Evented, {
181181
return Ember.RSVP.Promise.resolve(true);
182182
},
183183

184-
185-
186184
/**
187185
* Checks if the State returned from the server matches the state that was generated in the original request and saved in the browsers localStorage.
188186
*
@@ -236,7 +234,7 @@ export default Ember.Service.extend(Ember.Evented, {
236234
'&redirect_uri=' + encodeURIComponent(this.get('redirectUri')) +
237235
'&client_id=' + encodeURIComponent(this.get('clientId')) +
238236
'&state=' + encodeURIComponent(this.get('state'));
239-
if (this.get('scope')) {
237+
if (this.get('scope')) {
240238
uri += '&scope=' + encodeURIComponent(this.get('scope')).replace('%20', '+');
241239
}
242240
return uri;
@@ -350,7 +348,7 @@ export default Ember.Service.extend(Ember.Evented, {
350348

351349
/**
352350
* @method generateState
353-
* @return {String} The state
351+
* @return {String} The state
354352
*/
355353
generateState(clear = false) {
356354
if (!this.get('state') || clear === true) { this.set('state', this.uuid()); }
@@ -362,7 +360,7 @@ export default Ember.Service.extend(Ember.Evented, {
362360
* @return {Object} The params from the OAuth2 response from localStorage with the key 'tokenPrefix-providerId'.
363361
*/
364362
getToken: function() {
365-
var token = JSON.parse(window.localStorage.getItem(this.tokenKeyName()));
363+
var token = JSON.parse(window.localStorage.getItem(this.tokenKeyName()));
366364
if (!token) { return null; }
367365
if (!token.access_token) { return null; }
368366
return token;

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ember-oauth2",
3-
"version": "2.0.2-beta",
3+
"version": "2.0.3-beta",
44
"homepage": "https://github.com/amkirwan/ember-oauth2",
55
"authors": [
66
"Anthony Kirwan <[email protected]>"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ember-oauth2",
3-
"version": "2.0.2-beta",
3+
"version": "2.0.3-beta",
44
"description": "OAuth2 library for Emberjs that stores tokens in the browsers localStorage",
55
"homepage": "https://github.com/amkirwan/ember-ouath2",
66
"directories": {

tests/unit/ember-oauth-test.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import Ember from 'ember';
22
import { moduleFor, test } from 'ember-qunit';
33
import sinon from 'sinon';
44

5-
65
let service, responseType, clientId, authBaseUri, redirectUri, scopes;
76

87
moduleFor('service:ember-oauth2', 'Unit | Service | EmberOAuth2', {
@@ -48,7 +47,7 @@ test("#setProvider configures the provider from the providerId in the ember-oaut
4847
service.setProvider('test_auth');
4948
assert.expect(5);
5049
assert.equal(service.get('providerId'), 'test_auth');
51-
assert.deepEqual(service.get('providerConfig'), window.EmberENV['ember-oauth2']['test_auth']);
50+
assert.deepEqual(service.get('providerConfig'), window.EmberENV['ember-oauth2']['test_auth']);
5251
// sets the properties from the providerConfig
5352
assert.equal(service.get('clientId'), clientId);
5453
assert.equal(service.get('authBaseUri'), authBaseUri);
@@ -120,7 +119,7 @@ test('#removeState', function(assert) {
120119

121120
window.localStorage.setItem('foobar', {});
122121
assert.ok(window.localStorage.getItem('foobar'));
123-
service.removeState('foobar');
122+
service.removeState('foobar');
124123
assert.notOk(window.localStorage.getItem('foobar'));
125124

126125
// without stateName use saved stateKeyName;
@@ -156,7 +155,7 @@ test('remove any saved states with prefix', function(assert) {
156155
// requestObj
157156
test('#requestObj', function(assert) {
158157
let obj = service.requestObj();
159-
158+
160159
assert.equal(obj.response_type, 'token');
161160
assert.equal(obj.providerId, 'test_auth');
162161
assert.equal(obj.clientId, 'abcd');
@@ -282,7 +281,7 @@ test("#generateToken should generate the token that will be saved to the localSt
282281
let stub = sinon.stub(service, 'expiresIn', function() { return 1000; });
283282
let params = {expires_in: 1000, scope: scopes, access_token: 'abcd12345'};
284283
let token = { provider_id: 'test_auth', expires_in: 1000, scope: scopes, access_token: 'abcd12345' };
285-
284+
286285
assert.deepEqual(service.generateToken(params), token);
287286
stub.reset();
288287
});
@@ -311,7 +310,7 @@ test('#handleRedirect - success', function(assert) {
311310
'&token_type=' + 'Bearer' +
312311
'&expires_in=' + '3600' +
313312
'&state=' + state;
314-
313+
315314
let parsed = { access_token : '12345abc', token_type : 'Bearer', expires_in : '3600', state : state };
316315
let stub = sinon.stub(service, 'parseCallback', function() { return parsed; });
317316

@@ -336,7 +335,7 @@ test('#handleRedirect - verifyToken failure', function(assert) {
336335
'&token_type=' + 'Bearer' +
337336
'&expires_in=' + '3600' +
338337
'&state=' + state;
339-
338+
340339
let parsed = { access_token: '12345abc', token_type : 'Bearer', expires_in : '3600', state : state };
341340
let stub = sinon.stub(service, 'parseCallback', function() { return parsed; });
342341

@@ -361,7 +360,7 @@ test('#handleRedirect - failure state does not match', function(assert) {
361360
'&token_type=' + 'Bearer' +
362361
'&expires_in=' + '3600' +
363362
'&state=' + '12345';
364-
363+
365364
let parsed = { access_token: '12345abc', token_type : 'Bearer', expires_in : '3600', state : state };
366365
let stub = sinon.stub(service, 'parseCallback', function() { return parsed; });
367366

@@ -372,7 +371,7 @@ test('#handleRedirect - failure state does not match', function(assert) {
372371
});
373372

374373
// failure Implicit client-side flow
375-
// responseType is 'token' but response of the
374+
// responseType is 'token' but response of the
376375
// callbackUri is 'code' instead of 'token'
377376
test('#handleRedirect - tokenType is incorrect', function(assert) {
378377
let spy = sinon.spy(service, 'handleRedirect');
@@ -386,7 +385,7 @@ test('#handleRedirect - tokenType is incorrect', function(assert) {
386385
'&token_type=' + 'Bearer' +
387386
'&expires_in=' + '3600' +
388387
'&state=' + state;
389-
388+
390389
let parsed = { code: '12345abc', token_type : 'Bearer', expires_in : '3600', state : state };
391390
let stub = sinon.stub(service, 'parseCallback', function() { return parsed; });
392391

@@ -410,7 +409,7 @@ test('#handleRedirect - success authorization flow', function(assert) {
410409
'&token_type=' + 'Bearer' +
411410
'&expires_in=' + '3600' +
412411
'&state=' + state;
413-
412+
414413
let parsed = { code: '12345abc', token_type : 'Bearer', expires_in : '3600', state : state };
415414
let stub = sinon.stub(service, 'parseCallback', function() { return parsed; });
416415

@@ -465,7 +464,7 @@ test("#accessTokenIsExpired", function(assert) {
465464

466465
test("#expiresIn", function(assert) {
467466
let stub = sinon.stub(service, 'now', function() { return 1000; });
468-
467+
469468
assert.equal(service.expiresIn(3600), 4600);
470469
stub.reset();
471470
});
@@ -474,7 +473,7 @@ test("#removeToken", function(assert) {
474473
assert.expect(2);
475474
window.localStorage.removeItem(service.tokenKeyName());
476475
let token = {access_token: 'abcd', foo: 'bar'};
477-
service.saveToken(token);
476+
service.saveToken(token);
478477
assert.equal(window.localStorage.getItem(service.tokenKeyName()), JSON.stringify(token));
479478
service.removeToken();
480479
assert.equal(window.localStorage.getItem(service.tokenKeyName()), undefined);

yuidoc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Ember.OAuth2",
33
"description": "OAuth2 library for Emberjs that stores tokens in the browsers localStorage",
4-
"version": "2.0.2-beta",
4+
"version": "2.0.3-beta",
55
"url": "https://github.com/amkirwan/ember-oauth2",
66
"options": {
77
"exclude": "node_modules,bower_components,scripts,tmp,vendor",

0 commit comments

Comments
 (0)