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