diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..16e22a1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2014 Friðrik Már Jónsson + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.rst b/README.rst index 0a62add..e1463b4 100644 --- a/README.rst +++ b/README.rst @@ -4,7 +4,6 @@ About This project provides an implementation of a client-side (implicit grant) OAuth 2.0 authorization flow. - Features ======== @@ -37,7 +36,7 @@ Online Check out the demo by going to `example/demo.html via rawhithub.com`_. -.. _example/demo.html via rawhithub.com: https://rawgithub.com/enginous/angular-oauth/master/example/demo.html +.. _example/demo.html via rawhithub.com: https://rawgithub.com/angular-oauth/angular-oauth/master/example/demo.html Local diff --git a/component.json b/component.json index 5415b03..cc2ec68 100644 --- a/component.json +++ b/component.json @@ -4,9 +4,9 @@ "dependencies": { "angular": ">= 1.1.4" }, - "homepage": "https://github.com/enginous/angular-oauth", + "homepage": "https://github.com/angular-oauth/angular-oauth", "repository": { "type": "git", - "url": "git://github.com/enginous/angular-oauth.git" + "url": "git://github.com/angular-oauth/angular-oauth.git" } } diff --git a/src/js/angularOauth.js b/src/js/angularOauth.js index d244c63..52fa055 100644 --- a/src/js/angularOauth.js +++ b/src/js/angularOauth.js @@ -69,13 +69,18 @@ angular.module('angularOauth', []). // TODO: Facebook uses comma-delimited scopes. This is not compliant with section 3.3 but perhaps support later. return { - response_type: RESPONSE_TYPE, + response_type: config.responseType || RESPONSE_TYPE, client_id: config.clientId, redirect_uri: config.redirectUri, scope: config.scopes.join(" ") } }; + var buildAuthorizationUrl = function(extraParams) { + var params = angular.extend(getParams(), extraParams); + return config.authorizationEndpoint + '?' + objectToQueryString(params); + } + return { // TODO: get/set might want to support expiration to reauthenticate // TODO: check for localStorage support and otherwise perhaps use other methods of storing data (e.g. cookie) @@ -98,6 +103,13 @@ angular.module('angularOauth', []). localStorage[config.localStorageName] = accessToken; }, + /** + * Forgets the access token. + */ + clear: function() { + localStorage.removeItem(config.localStorageName); + }, + /** * Verifies that the access token is was issued for the use of the current client. * @@ -121,7 +133,7 @@ angular.module('angularOauth', []). /** * Verifies an access token asynchronously. * - * @param extraParams An access token received from the authorization server. + * @param extraParams Additional params to be appended to the query string of the request. * @param popupOptions Settings for the display of the popup. * @returns {Promise} Promise that will be resolved when the authorization server has verified that the * token is valid, and we've verified that the token is passed back has audience that matches our client @@ -148,8 +160,7 @@ angular.module('angularOauth', []). }, popupOptions); var deferred = $q.defer(), - params = angular.extend(getParams(), extraParams), - url = config.authorizationEndpoint + '?' + objectToQueryString(params), + url = buildAuthorizationUrl(extraParams), resolved = false; var formatPopupOptions = function(options) { @@ -168,6 +179,8 @@ angular.module('angularOauth', []). // TODO: binding occurs for each reauthentication, leading to leaks for long-running apps. angular.element($window).bind('message', function(event) { + // Use JQuery originalEvent if present + event = event.originalEvent || event; if (event.source == popup && event.origin == window.location.origin) { $rootScope.$apply(function() { if (event.data.access_token) { @@ -182,6 +195,10 @@ angular.module('angularOauth', []). // TODO: reject deferred if the popup was closed without a message being delivered + maybe offer a timeout return deferred.promise; + }, + getTokenInSameWindow: function(extraParams) { + var url = buildAuthorizationUrl(extraParams); + $window.location.href = url; } } }