Generate QR with access token for given user

fixes https://gitlab.com/entgra/product-iots/-/issues/1277
merge-requests/867/head
inoshperera 3 years ago
parent aa2234dcdd
commit 51cd59f436

@ -62,11 +62,13 @@ public interface APIManagementProviderService {
* @param applicationName Application Name
* @param tokenType Token Type
* @param validityPeriod Validity Period
* @param username Name of the user to create the token. If null, set as carbon context user
* @return {@link String} Access Token
* @throws APIManagerException if error occurred while getting the access token for given scopes,
* validity period etc.
*/
AccessTokenInfo getAccessToken(String scopes, String[] tags, String applicationName, String tokenType, String validityPeriod)
AccessTokenInfo getAccessToken(String scopes, String[] tags, String applicationName, String
tokenType, String validityPeriod, String username)
throws APIManagerException;
}

@ -233,7 +233,7 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
@Override
public AccessTokenInfo getAccessToken(String scopes, String[] tags, String applicationName, String tokenType,
String validityPeriod) throws APIManagerException {
String validityPeriod, String username) throws APIManagerException {
try {
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true);
ApiApplicationKey clientCredentials = getClientCredentials(tenantDomain, tags, applicationName, tokenType,
@ -245,15 +245,22 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
throw new APIManagerException(msg);
}
String user =
PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername() + "@" + PrivilegedCarbonContext
if (username == null || username.isEmpty()) {
username =
PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername() + "@" + PrivilegedCarbonContext
.getThreadLocalCarbonContext().getTenantDomain(true);
} else {
if (!username.contains("@")) {
username += "@" + PrivilegedCarbonContext
.getThreadLocalCarbonContext().getTenantDomain(true);
}
}
JWTClientManagerService jwtClientManagerService = APIApplicationManagerExtensionDataHolder.getInstance()
.getJwtClientManagerService();
JWTClient jwtClient = jwtClientManagerService.getJWTClient();
AccessTokenInfo accessTokenForAdmin = jwtClient
.getAccessToken(clientCredentials.getConsumerKey(), clientCredentials.getConsumerSecret(), user,
.getAccessToken(clientCredentials.getConsumerKey(), clientCredentials.getConsumerSecret(), username,
scopes);
return accessTokenForAdmin;

Loading…
Cancel
Save