Skip to content

Commit 2f0cdd0

Browse files
committed
add convenience method
1 parent ab2ce18 commit 2f0cdd0

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<modelVersion>4.0.0</modelVersion>
1212
<artifactId>oauth-token-manager</artifactId>
13-
<version>1.0.4</version>
13+
<version>1.0.5</version>
1414
<name>OauthTokenManager</name>
1515
<packaging>jar</packaging>
1616

src/main/java/info/unterrainer/oauthtokenmanager/OauthTokenManager.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ private TokenVerifier<AccessToken> persistUserInfoInContext(String authorization
138138
}
139139
}
140140

141+
public LocalOauthTokens getTokensFromCredentials(String clientId, String username, String password) {
142+
return getTokensFromCredentials(clientId, null, username, password);
143+
}
144+
141145
public LocalOauthTokens getTokensFromCredentials(String clientId, String clientSecret, String username,
142146
String password) {
143147
try {
@@ -148,8 +152,10 @@ public LocalOauthTokens getTokensFromCredentials(String clientId, String clientS
148152

149153
String form = "grant_type=password" + "&client_id=" + URLEncoder.encode(clientId, StandardCharsets.UTF_8)
150154
+ "&username=" + URLEncoder.encode(username, StandardCharsets.UTF_8) + "&password="
151-
+ URLEncoder.encode(password, StandardCharsets.UTF_8) + "&client_secret="
152-
+ URLEncoder.encode(clientSecret, StandardCharsets.UTF_8);
155+
+ URLEncoder.encode(password, StandardCharsets.UTF_8);
156+
if (clientSecret != null) {
157+
form += "&client_secret=" + URLEncoder.encode(clientSecret, StandardCharsets.UTF_8);
158+
}
153159

154160
HttpRequest request = HttpRequest.newBuilder()
155161
.uri(URI.create(tokenEndpoint))

0 commit comments

Comments
 (0)