Commit 49e6b52a by Jeffrey Phillips Committed by GitHub

Merge pull request #151 from david-martin/allow-oauth-scope-config

Allow OAuth scope(s) to be configured
parents d07857a2 0a82ae7d
......@@ -3171,6 +3171,7 @@ angular.module('openshiftCommonServices')
var _oauth_authorize_uri = "";
var _oauth_token_uri = "";
var _oauth_redirect_uri = "";
var _oauth_scope = "";
this.OAuthClientID = function(id) {
if (id) {
......@@ -3196,6 +3197,12 @@ angular.module('openshiftCommonServices')
}
return _oauth_redirect_uri;
};
this.OAuthScope = function(scope) {
if (scope) {
_oauth_scope = scope;
}
return _oauth_scope;
}
this.$get = function($injector, $location, $q, Logger, base64) {
var authLogger = Logger.get("auth");
......@@ -3286,6 +3293,10 @@ angular.module('openshiftCommonServices')
redirect_uri: _oauth_redirect_uri
};
if (_oauth_scope) {
authorizeParams.scope = _oauth_scope;
}
if (_oauth_token_uri) {
authorizeParams.response_type = "code";
// TODO: add PKCE
......@@ -3377,6 +3388,10 @@ angular.module('openshiftCommonServices')
"client_id=" + encodeURIComponent(_oauth_client_id)
].join("&");
if (_oauth_scope) {
tokenPostData += "&scope=" + encodeURIComponent(_oauth_scope);
}
return http({
method: "POST",
url: _oauth_token_uri,
......
......@@ -5039,6 +5039,7 @@ angular.module('openshiftCommonServices')
var _oauth_authorize_uri = "";
var _oauth_token_uri = "";
var _oauth_redirect_uri = "";
var _oauth_scope = "";
this.OAuthClientID = function(id) {
if (id) {
......@@ -5064,6 +5065,12 @@ angular.module('openshiftCommonServices')
}
return _oauth_redirect_uri;
};
this.OAuthScope = function(scope) {
if (scope) {
_oauth_scope = scope;
}
return _oauth_scope;
}
this.$get = ["$injector", "$location", "$q", "Logger", "base64", function($injector, $location, $q, Logger, base64) {
var authLogger = Logger.get("auth");
......@@ -5154,6 +5161,10 @@ angular.module('openshiftCommonServices')
redirect_uri: _oauth_redirect_uri
};
if (_oauth_scope) {
authorizeParams.scope = _oauth_scope;
}
if (_oauth_token_uri) {
authorizeParams.response_type = "code";
// TODO: add PKCE
......@@ -5245,6 +5256,10 @@ angular.module('openshiftCommonServices')
"client_id=" + encodeURIComponent(_oauth_client_id)
].join("&");
if (_oauth_scope) {
tokenPostData += "&scope=" + encodeURIComponent(_oauth_scope);
}
return http({
method: "POST",
url: _oauth_token_uri,
......
......@@ -2095,7 +2095,7 @@ orderByMostRecentlyViewed:orderByMostRecentlyViewed,
clear:clear
};
} ]), angular.module("openshiftCommonServices").provider("RedirectLoginService", function() {
var _oauth_client_id = "", _oauth_authorize_uri = "", _oauth_token_uri = "", _oauth_redirect_uri = "";
var _oauth_client_id = "", _oauth_authorize_uri = "", _oauth_token_uri = "", _oauth_redirect_uri = "", _oauth_scope = "";
this.OAuthClientID = function(id) {
return id && (_oauth_client_id = id), _oauth_client_id;
}, this.OAuthAuthorizeURI = function(uri) {
......@@ -2104,6 +2104,8 @@ return uri && (_oauth_authorize_uri = uri), _oauth_authorize_uri;
return uri && (_oauth_token_uri = uri), _oauth_token_uri;
}, this.OAuthRedirectURI = function(uri) {
return uri && (_oauth_redirect_uri = uri), _oauth_redirect_uri;
}, this.OAuthScope = function(scope) {
return scope && (_oauth_scope = scope), _oauth_scope;
}, this.$get = [ "$injector", "$location", "$q", "Logger", "base64", function($injector, $location, $q, Logger, base64) {
var authLogger = Logger.get("auth"), getRandomInts = function(length) {
var randomValues;
......@@ -2168,7 +2170,7 @@ response_type:"token",
state:makeState(returnUri.toString()),
redirect_uri:_oauth_redirect_uri
};
_oauth_token_uri && (authorizeParams.response_type = "code");
_oauth_scope && (authorizeParams.scope = _oauth_scope), _oauth_token_uri && (authorizeParams.response_type = "code");
var deferred = $q.defer(), uri = new URI(_oauth_authorize_uri);
return uri.query(authorizeParams), authLogger.log("RedirectLoginService.login(), redirecting", uri.toString()), window.location.href = uri.toString(), deferred.promise;
},
......@@ -2198,7 +2200,7 @@ error:"invalid_request",
error_description:"Client state could not be verified"
});
var tokenPostData = [ "grant_type=authorization_code", "code=" + encodeURIComponent(queryParams.code), "redirect_uri=" + encodeURIComponent(_oauth_redirect_uri), "client_id=" + encodeURIComponent(_oauth_client_id) ].join("&");
return http({
return _oauth_scope && (tokenPostData += "&scope=" + encodeURIComponent(_oauth_scope)), http({
method:"POST",
url:_oauth_token_uri,
headers:{
......
......@@ -7,6 +7,7 @@ angular.module('openshiftCommonServices')
var _oauth_authorize_uri = "";
var _oauth_token_uri = "";
var _oauth_redirect_uri = "";
var _oauth_scope = "";
this.OAuthClientID = function(id) {
if (id) {
......@@ -32,6 +33,12 @@ angular.module('openshiftCommonServices')
}
return _oauth_redirect_uri;
};
this.OAuthScope = function(scope) {
if (scope) {
_oauth_scope = scope;
}
return _oauth_scope;
}
this.$get = function($injector, $location, $q, Logger, base64) {
var authLogger = Logger.get("auth");
......@@ -122,6 +129,10 @@ angular.module('openshiftCommonServices')
redirect_uri: _oauth_redirect_uri
};
if (_oauth_scope) {
authorizeParams.scope = _oauth_scope;
}
if (_oauth_token_uri) {
authorizeParams.response_type = "code";
// TODO: add PKCE
......@@ -213,6 +224,10 @@ angular.module('openshiftCommonServices')
"client_id=" + encodeURIComponent(_oauth_client_id)
].join("&");
if (_oauth_scope) {
tokenPostData += "&scope=" + encodeURIComponent(_oauth_scope);
}
return http({
method: "POST",
url: _oauth_token_uri,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment