Skip to content
This repository was archived by the owner on Dec 9, 2025. It is now read-only.

Commit f6aa138

Browse files
committed
update dice endpoints
1 parent e1ea805 commit f6aa138

File tree

7 files changed

+15
-175
lines changed

7 files changed

+15
-175
lines changed

buildtokenproperties.sh

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@ AUTH0_NEW_NONINTERACTIVE_ID_SECRET=$(eval "echo \$${ENV}_AUTH0_NEW_NONINTERACTIV
1818
DICEAUTH_DICE_URL=$(eval "echo \$${ENV}_DICEAUTH_DICE_URL")
1919
DICEAUTH_DICE_API_URL=$(eval "echo \$${ENV}_DICEAUTH_DICE_API_URL")
2020
DICEAUTH_DICE_VERIFIER=$(eval "echo \$${ENV}_DICEAUTH_DICE_VERIFIER")
21-
DICEAUTH_ID=$(eval "echo \$${ENV}_DICEAUTH_ID")
22-
DICEAUTH_ID_SECRET=$(eval "echo \$${ENV}_DICEAUTH_ID_SECRET")
23-
DICEAUTH_PASSWORD=$(eval "echo \$${ENV}_DICEAUTH_PASSWORD")
24-
DICEAUTH_SCOPE=$(eval "echo \$${ENV}_DICEAUTH_SCOPE")
25-
DICEAUTH_TENANT=$(eval "echo \$${ENV}_DICEAUTH_TENANT")
26-
DICEAUTH_USERNAME=$(eval "echo \$${ENV}_DICEAUTH_USERNAME")
21+
DICEAUTH_DICE_API_KEY=$(eval "echo \$${ENV}_DICEAUTH_DICE_API_KEY")
2722
DICEAUTH_CREDDEFID=$(eval "echo \$${ENV}_DICEAUTH_CREDDEFID")
2823
ZENDESK_ID=$(eval "echo \$${ENV}_ZENDESK_ID")
2924
SERVICEACC02_UID=$(eval "echo \$${ENV}_SERVICEACC02_UID")
@@ -97,12 +92,7 @@ perl -pi -e "s/\{\{AUTH0_NEW_NONINTERACTIVE_ID_SECRET\}\}/$AUTH0_NEW_NONINTERACT
9792
perl -pi -e "s|\{\{DICEAUTH_DICE_URL\}\}|$DICEAUTH_DICE_URL|g" $CONFFILENAME
9893
perl -pi -e "s|\{\{DICEAUTH_DICE_API_URL\}\}|$DICEAUTH_DICE_API_URL|g" $CONFFILENAME
9994
perl -pi -e "s|\{\{DICEAUTH_DICE_VERIFIER\}\}|$DICEAUTH_DICE_VERIFIER|g" $CONFFILENAME
100-
perl -pi -e "s/\{\{DICEAUTH_ID\}\}/$DICEAUTH_ID/g" $CONFFILENAME
101-
perl -pi -e "s/\{\{DICEAUTH_ID_SECRET\}\}/$DICEAUTH_ID_SECRET/g" $CONFFILENAME
102-
perl -pi -e "s|\{\{DICEAUTH_PASSWORD\}\}|$DICEAUTH_PASSWORD|g" $CONFFILENAME
103-
perl -pi -e "s/\{\{DICEAUTH_SCOPE\}\}/$DICEAUTH_SCOPE/g" $CONFFILENAME
104-
perl -pi -e "s/\{\{DICEAUTH_TENANT\}\}/$DICEAUTH_TENANT/g" $CONFFILENAME
105-
perl -pi -e "s/\{\{DICEAUTH_USERNAME\}\}/$DICEAUTH_USERNAME/g" $CONFFILENAME
95+
perl -pi -e "s|\{\{DICEAUTH_DICE_API_KEY\}\}|$DICEAUTH_DICE_API_KEY|g" $CONFFILENAME
10696
perl -pi -e "s/\{\{DICEAUTH_CREDDEFID\}\}/$DICEAUTH_CREDDEFID/g" $CONFFILENAME
10797
perl -pi -e "s/\{\{ZENDESK_KEY\}\}/$ZENDESK_KEY/g" $CONFFILENAME
10898
perl -pi -e "s/\{\{ZENDESK_ID\}\}/$ZENDESK_ID/g" $CONFFILENAME

src/main/java/com/appirio/tech/core/service/identity/resource/UserResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,7 @@ public ApiResponse updateUser2fa(
15491549
try {
15501550
response = new Request(diceAuth.getDiceApiUrl() + "/connection/invitation", "POST")
15511551
.param("emailId", user2faInDb.getEmail())
1552-
.header("Authorization", "Bearer " + diceAuth.getToken())
1552+
.header("x-api-key", diceAuth.getDiceApiKey())
15531553
.execute();
15541554
} catch (Exception e) {
15551555
logger.error("Error when calling 2fa submit api", e);
@@ -1625,7 +1625,7 @@ public ApiResponse issueCredentials(
16251625
Response response;
16261626
try {
16271627
response = new Request(diceAuth.getDiceApiUrl() + "/cred/issuance/offer", "POST")
1628-
.header("Authorization", "Bearer " + diceAuth.getToken())
1628+
.header("x-api-key", diceAuth.getDiceApiKey())
16291629
.json(mapper.writeValueAsString(body))
16301630
.execute();
16311631
} catch (JsonProcessingException e) {
Lines changed: 7 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
11
package com.appirio.tech.core.service.identity.util.auth;
22

3-
import java.net.HttpURLConnection;
4-
import java.util.Date;
5-
63
import javax.validation.constraints.NotNull;
74

8-
import org.apache.log4j.Logger;
9-
10-
import com.appirio.tech.core.api.v3.exception.APIRuntimeException;
11-
import com.appirio.tech.core.api.v3.util.jwt.InvalidTokenException;
12-
import com.appirio.tech.core.service.identity.util.HttpUtil.Request;
13-
import com.appirio.tech.core.service.identity.util.HttpUtil.Response;
14-
import com.auth0.jwt.JWT;
15-
import com.auth0.jwt.exceptions.JWTDecodeException;
16-
import com.auth0.jwt.interfaces.DecodedJWT;
17-
import com.fasterxml.jackson.databind.ObjectMapper;
18-
195
public class DICEAuth {
20-
private static final Logger logger = Logger.getLogger(Auth0Client.class);
216

227
@NotNull
238
private String diceUrl;
@@ -29,44 +14,21 @@ public class DICEAuth {
2914
private String diceVerifier;
3015

3116
@NotNull
32-
private String tenant;
33-
34-
@NotNull
35-
private String username;
36-
37-
@NotNull
38-
private String password;
39-
40-
@NotNull
41-
private String scope;
42-
43-
@NotNull
44-
private String clientId;
45-
46-
@NotNull
47-
private String clientSecret;
17+
private String diceApiKey;
4818

4919
@NotNull
5020
private String credDefId;
5121

5222
private String credPreview = "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/issue-credential/1.0/credential-preview";
5323

54-
private String cachedToken;
55-
5624
public DICEAuth() {
5725
}
5826

59-
public DICEAuth(String diceUrl, String diceApiUrl, String diceVerifier, String tenant, String username,
60-
String password, String scope, String clientId, String clientSecret, String credDefId) {
27+
public DICEAuth(String diceUrl, String diceApiUrl, String diceVerifier, String diceApiKey, String credDefId) {
6128
this.diceUrl = diceUrl;
6229
this.diceApiUrl = diceApiUrl;
6330
this.diceVerifier = diceVerifier;
64-
this.tenant = tenant;
65-
this.username = username;
66-
this.password = password;
67-
this.scope = scope;
68-
this.clientId = clientId;
69-
this.clientSecret = clientSecret;
31+
this.diceApiKey = diceApiKey;
7032
this.credDefId = credDefId;
7133
}
7234

@@ -94,52 +56,12 @@ public void setDiceVerifier(String diceVerifier) {
9456
this.diceVerifier = diceVerifier;
9557
}
9658

97-
public String getTenant() {
98-
return tenant;
99-
}
100-
101-
public void setTenant(String tenant) {
102-
this.tenant = tenant;
103-
}
104-
105-
public String getUsername() {
106-
return username;
107-
}
108-
109-
public void setUsername(String username) {
110-
this.username = username;
111-
}
112-
113-
public String getPassword() {
114-
return password;
115-
}
116-
117-
public void setPassword(String password) {
118-
this.password = password;
59+
public String getDiceApiKey() {
60+
return diceApiKey;
11961
}
12062

121-
public String getScope() {
122-
return scope;
123-
}
124-
125-
public void setScope(String scope) {
126-
this.scope = scope;
127-
}
128-
129-
public String getClientId() {
130-
return clientId;
131-
}
132-
133-
public void setClientId(String clientId) {
134-
this.clientId = clientId;
135-
}
136-
137-
public String getClientSecret() {
138-
return clientSecret;
139-
}
140-
141-
public void setClientSecret(String clientSecret) {
142-
this.clientSecret = clientSecret;
63+
public void setDiceApiKey(String diceApiKey) {
64+
this.diceApiKey = diceApiKey;
14365
}
14466

14567
public String getCredDefId() {
@@ -157,56 +79,4 @@ public String getCredPreview() {
15779
public void setCredPreview(String credPreview) {
15880
this.credPreview = credPreview;
15981
}
160-
161-
public String getToken() throws Exception {
162-
Boolean isCachedTokenExpired = false;
163-
if (cachedToken != null) {
164-
if (getTokenExpiryTime(cachedToken) <= 0) {
165-
isCachedTokenExpired = true;
166-
logger.info("Application cached token expired");
167-
}
168-
}
169-
if (cachedToken == null || isCachedTokenExpired) {
170-
String url = "https://login.microsoftonline.com/" + getTenant() + "/oauth2/v2.0/token";
171-
Response response = new Request(url, "POST")
172-
.param("grant_type", "password")
173-
.param("username", getUsername())
174-
.param("password", getPassword())
175-
.param("scope", getScope())
176-
.param("client_id", getClientId())
177-
.param("client_secret", getClientSecret()).execute();
178-
if (response.getStatusCode() != HttpURLConnection.HTTP_OK) {
179-
throw new APIRuntimeException(HttpURLConnection.HTTP_INTERNAL_ERROR,
180-
String.format("Got unexpected response from remote service. %d %s", response.getStatusCode(),
181-
response.getText()));
182-
}
183-
cachedToken = new ObjectMapper().readValue(response.getText(), Auth0Credential.class).getIdToken();
184-
logger.info("Fetched token from URL: " + url);
185-
}
186-
return cachedToken;
187-
}
188-
189-
/**
190-
* Get token expiry time in seconds
191-
*
192-
* @param token JWT token
193-
* throws Exception if any error occurs
194-
* @return the Integer result
195-
*/
196-
private Integer getTokenExpiryTime(String token) throws Exception {
197-
DecodedJWT decodedJWT = null;
198-
Integer tokenExpiryTime = 0;
199-
if (token != null) {
200-
try {
201-
decodedJWT = JWT.decode(token);
202-
} catch (JWTDecodeException e) {
203-
throw new InvalidTokenException(token, "Error occurred in decoding token. " + e.getLocalizedMessage(),
204-
e);
205-
}
206-
Date tokenExpiryDate = decodedJWT.getExpiresAt();
207-
Long tokenExpiryTimeInMilliSeconds = tokenExpiryDate.getTime() - (new Date().getTime()) - 60 * 1000;
208-
tokenExpiryTime = (int) Math.floor(tokenExpiryTimeInMilliSeconds / 1000);
209-
}
210-
return tokenExpiryTime;
211-
}
21282
}

src/main/resources/config.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,7 @@ diceAuth:
9797
diceUrl: @diceAuth.diceUrl@
9898
diceApiUrl: @diceAuth.diceApiUrl@
9999
diceVerifier: @diceAuth.diceVerifier@
100-
clientId: @diceAuth.clientId@
101-
clientSecret: @diceAuth.clientSecret@
102-
password: @diceAuth.password@
103-
scope: @diceAuth.scope@
104-
tenant: @diceAuth.tenant@
105-
username: @diceAuth.username@
100+
diceApiKey: @diceAuth.diceApiKey@
106101
credDefId: @diceAuth.credDefId@
107102

108103
# Authorized accounts

src/main/resources/config.yml.localdev

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,7 @@ diceAuth:
8989
diceUrl: dummy
9090
diceApiUrl: dummy
9191
diceVerifier: dummy
92-
clientId: dummy
93-
clientSecret: dummy
94-
password: dummy
95-
scope: dummy
96-
tenant: dummy
97-
username: dummy
92+
diceApiKey: dummy
9893
credDefId: dummy
9994

10095
# LDAP Settings

token.properties.localdev

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@
3434
@diceAuth.diceUrl@=dummy
3535
@diceAuth.diceApiUrl@=dummy
3636
@diceAuth.diceVerifier@=dummy
37-
@diceAuth.clientId@=dummy
38-
@diceAuth.clientSecret@=dummy
39-
@diceAuth.password@=dummy
40-
@diceAuth.scope@=dummy
41-
@diceAuth.tenant@=dummy
42-
@diceAuth.username@=dummy
37+
@diceAuth.diceApiKey@=dummy
4338
@diceAuth.credDefId@=dummy
4439

4540
@zendesk.secret@=ZENDESK_SECRET

token.properties.template

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,7 @@
5454
@diceAuth.diceUrl@={{DICEAUTH_DICE_URL}}
5555
@diceAuth.diceApiUrl@={{DICEAUTH_DICE_API_URL}}
5656
@diceAuth.diceVerifier@={{DICEAUTH_DICE_VERIFIER}}
57-
@diceAuth.clientId@={{DICEAUTH_ID}}
58-
@diceAuth.clientSecret@={{DICEAUTH_ID_SECRET}}
59-
@diceAuth.password@={{DICEAUTH_PASSWORD}}
60-
@diceAuth.scope@={{DICEAUTH_SCOPE}}
61-
@diceAuth.tenant@={{DICEAUTH_TENANT}}
62-
@diceAuth.username@={{DICEAUTH_USERNAME}}
57+
@diceAuth.diceApiKey@={{DICEAUTH_DICE_API_KEY}}
6358
@diceAuth.credDefId@={{DICEAUTH_CREDDEFID}}
6459

6560
@zendesk.secret@={{ZENDESK_KEY}}

0 commit comments

Comments
 (0)