|
|
|
@ -80,11 +80,11 @@ var utils = function () {
|
|
|
|
|
return dynamicClientAppCredentials;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
publicMethods["getTenantBasedClientAppCredentials"] = function (username, jwtToken) {
|
|
|
|
|
if (!username || !jwtToken) {
|
|
|
|
|
publicMethods["getTenantBasedClientAppCredentials"] = function (username) {
|
|
|
|
|
if (!username) {
|
|
|
|
|
log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving tenant " +
|
|
|
|
|
"based client app credentials. No username or jwt token is found " +
|
|
|
|
|
"as input - getTenantBasedClientAppCredentials(x, y)");
|
|
|
|
|
"based client app credentials. No username " +
|
|
|
|
|
"as input - getTenantBasedClientAppCredentials(x)");
|
|
|
|
|
return null;
|
|
|
|
|
} else {
|
|
|
|
|
//noinspection JSUnresolvedFunction, JSUnresolvedVariable
|
|
|
|
@ -100,6 +100,12 @@ var utils = function () {
|
|
|
|
|
if (cachedTenantBasedClientAppCredentials) {
|
|
|
|
|
return cachedTenantBasedClientAppCredentials;
|
|
|
|
|
} else {
|
|
|
|
|
var adminUsername = deviceMgtProps["adminUser"];
|
|
|
|
|
//claims required for jwtAuthenticator.
|
|
|
|
|
var claims = {"http://wso2.org/claims/enduserTenantId": "-1234",
|
|
|
|
|
"http://wso2.org/claims/enduser": adminUsername};
|
|
|
|
|
var jwtToken = publicMethods.getJwtToken(adminUsername, claims);
|
|
|
|
|
|
|
|
|
|
// register a tenant based client app at API Manager
|
|
|
|
|
var applicationName = "webapp_" + tenantDomain;
|
|
|
|
|
var requestURL = deviceMgtProps["oauthProvider"]["appRegistration"]
|
|
|
|
@ -109,7 +115,7 @@ var utils = function () {
|
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
|
xhr.open("POST", requestURL, false);
|
|
|
|
|
xhr.setRequestHeader("Content-Type", "application/json");
|
|
|
|
|
xhr.setRequestHeader("Authorization", "X-JWT-Assertion " + jwtToken);
|
|
|
|
|
xhr.setRequestHeader("X-JWT-Assertion", "" + jwtToken);
|
|
|
|
|
xhr.send();
|
|
|
|
|
|
|
|
|
|
if (xhr["status"] == 201 && xhr["responseText"]) {
|
|
|
|
@ -291,7 +297,7 @@ var utils = function () {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
publicMethods["getJwtToken"] = function (username) {
|
|
|
|
|
publicMethods["getJwtToken"] = function (username, claims) {
|
|
|
|
|
if (!username) {
|
|
|
|
|
log.error("{/app/modules/oauth/token-handler-utils.js} Error in retrieving new jwt token");
|
|
|
|
|
return null;
|
|
|
|
@ -303,8 +309,13 @@ var utils = function () {
|
|
|
|
|
//noinspection JSUnresolvedFunction
|
|
|
|
|
var jwtClient = JWTClientManagerService.getJWTClient();
|
|
|
|
|
// returning access token by JWT grant type
|
|
|
|
|
if (claims) {
|
|
|
|
|
return jwtClient.getJwtToken(username, claims);
|
|
|
|
|
} else {
|
|
|
|
|
return jwtClient.getJwtToken(username);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return publicMethods;
|
|
|
|
|