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

Commit eaffb61

Browse files
author
Jason
authored
Add id_token to OAuthGrantRequestAuthenticationResult (#1230)
#1229 Add id_token to OAuthGrantRequestAuthenticationResult
1 parent 17a5f49 commit eaffb61

File tree

10 files changed

+72
-9
lines changed

10 files changed

+72
-9
lines changed

api/src/main/java/com/stormpath/sdk/oauth/GrantAuthenticationToken.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ public interface GrantAuthenticationToken extends Resource {
3838
*/
3939
public String getRefreshToken();
4040

41+
/**
42+
* Returns the value denoting the id token of the response as a <a href="https://en.wikipedia.org/wiki/JSON_Web_Token">Json Web Token</a> for certain requests.
43+
* The details of id_token are described in the <a href="http://openid.net/specs/openid-connect-core-1_0.html#IDToken">OpenID Connect spec</a>.
44+
* @return the String value denoting the id token of the response or null if there is no id token returned
45+
* @since 1.4.0
46+
*/
47+
public String getIdToken();
48+
4149
/**
4250
* Returns the type of the token included in the response.
4351
*

api/src/main/java/com/stormpath/sdk/oauth/OAuthGrantRequestAuthenticationResult.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ public interface OAuthGrantRequestAuthenticationResult extends OAuthRequestAuthe
3737
*/
3838
AccessToken getAccessToken();
3939

40+
41+
/**
42+
* Returns the String that corresponds to the OpenID Connect id_token (if present) created during the Create Grant
43+
* Authentication operation.
44+
* @return the String representation of the OpenID Connect id_token
45+
* @since 1.4.0
46+
*/
47+
String getIdTokenString();
48+
4049
/**
4150
* Returns the String that corresponds to the token created during the Refresh Grant Authentication operation.
4251
* @return the String representation of the Oauth refresh token

api/src/main/java/com/stormpath/sdk/oauth/TokenResponse.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ public interface TokenResponse {
5959
*/
6060
String getAccessToken();
6161

62+
/**
63+
* Returns the Id Token string that should be used by the client as defined in the OpenID Connect spec.
64+
* @return the Id Token string that should be used by the client as defined in the OpenID Connect spec.
65+
* @since 1.4.0
66+
*/
67+
String getIdToken();
68+
6269
/**
6370
* Returns the space separated collection of granted scopes.
6471
*

extensions/oauth/src/main/java/com/stormpath/sdk/impl/oauth/authz/DefaultTokenResponse.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ public class DefaultTokenResponse implements TokenResponse {
2727
private final String applicationHref;
2828

2929
private final OAuthResponse oAuthResponse;
30+
private final String idToken;
3031

3132
private DefaultTokenResponse(Builder builder) {
3233
accessToken = builder.accessToken;
3334
expiresIn = builder.expiresIn;
3435
refreshToken = builder.refreshToken;
36+
idToken = builder.idToken;
3537
scope = builder.scope;
3638
tokenType = builder.tokenType;
3739
applicationHref = builder.applicationHref;
@@ -52,6 +54,11 @@ public String getAccessToken() {
5254
return accessToken;
5355
}
5456

57+
@Override
58+
public String getIdToken() {
59+
return idToken;
60+
}
61+
5562
@Override
5663
public String getScope() {
5764
return scope;
@@ -93,6 +100,7 @@ public static class Builder {
93100
private String scope;
94101
private String tokenType;
95102
private String applicationHref;
103+
private String idToken;
96104

97105
private OAuthASResponse.OAuthTokenResponseBuilder tokenResponseBuilder;
98106

@@ -108,6 +116,11 @@ public Builder accessToken(String accessToken) {
108116
return this;
109117
}
110118

119+
public Builder idToken(String idToken) {
120+
this.idToken = idToken;
121+
return this;
122+
}
123+
111124
public Builder scope(String scope) {
112125
this.scope = scope;
113126
tokenResponseBuilder.setScope(scope);

extensions/servlet/src/main/java/com/stormpath/sdk/servlet/filter/oauth/DefaultAccessTokenResultFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public AccessTokenResult createAccessTokenResult(HttpServletRequest request, Htt
4848
DefaultTokenResponse.tokenType(TokenType.BEARER)
4949
.accessToken(result.getAccessTokenString())
5050
.refreshToken(result.getRefreshTokenString())
51+
.idToken(result.getIdTokenString())
5152
.applicationHref(application.getHref())
5253
.expiresIn(String.valueOf(result.getExpiresIn())).build();
5354
return new PasswordGrantAccessTokenResult(result.getAccessToken().getAccount(), tokenResponse);

impl/src/main/java/com/stormpath/sdk/impl/oauth/DefaultGrantAuthenticationToken.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434
public class DefaultGrantAuthenticationToken extends AbstractInstanceResource implements GrantAuthenticationToken {
3535

3636
static final StringProperty ACCESS_TOKEN = new StringProperty("access_token");
37+
static final StringProperty ID_TOKEN = new StringProperty("id_token");
3738
static final StringProperty REFRESH_TOKEN = new StringProperty("refresh_token");
3839
static final StringProperty TOKEN_TYPE = new StringProperty("token_type");
3940
static final StringProperty EXPIRES_IN = new StringProperty("expires_in");
4041
static final StringProperty ACCESS_TOKEN_HREF = new StringProperty("stormpath_access_token_href");
41-
42-
static final Map<String, Property> PROPERTY_DESCRIPTORS = createPropertyDescriptorMap(ACCESS_TOKEN, REFRESH_TOKEN, EXPIRES_IN, TOKEN_TYPE, ACCESS_TOKEN_HREF);
42+
static final Map<String, Property> PROPERTY_DESCRIPTORS = createPropertyDescriptorMap(ACCESS_TOKEN, REFRESH_TOKEN, ID_TOKEN, EXPIRES_IN, TOKEN_TYPE, ACCESS_TOKEN_HREF);
4343

4444
public DefaultGrantAuthenticationToken(InternalDataStore dataStore) {
4545
super(dataStore);
@@ -62,6 +62,10 @@ public String getRefreshToken() {
6262
return getString(REFRESH_TOKEN);
6363
}
6464

65+
public String getIdToken() {
66+
return getString(ID_TOKEN);
67+
}
68+
6569
public String getTokenType() {
6670
return getString(TOKEN_TYPE);
6771
}
@@ -75,7 +79,7 @@ public String getAccessTokenHref() {
7579
}
7680

7781
public AccessToken getAsAccessToken(){
78-
Map<String, Object> props = new LinkedHashMap<String, Object>(1);
82+
Map<String, Object> props = new LinkedHashMap<>(1);
7983
props.put("href", this.getAccessTokenHref());
8084
return getDataStore().instantiate(AccessToken.class, props);
8185
}
@@ -89,7 +93,7 @@ public RefreshToken getAsRefreshToken() {
8993
}
9094

9195
Jws<Claims> jws = AbstractBaseOAuthToken.parseJws(refreshToken, getDataStore());
92-
Map<String, Object> props = new LinkedHashMap<String, Object>(1);
96+
Map<String, Object> props = new LinkedHashMap<>(1);
9397
String refreshTokenID = jws.getBody().getId();
9498
props.put("href", getDataStore().getBaseUrl() + "/refreshTokens/" + refreshTokenID);
9599
return getDataStore().instantiate(RefreshToken.class, props);

impl/src/main/java/com/stormpath/sdk/impl/oauth/DefaultOAuthClientCredentialsGrantRequestAuthenticationResultBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public DefaultOAuthGrantRequestAuthenticationResult build() {
1818

1919
this.accessToken = grantAuthenticationToken.getAsAccessToken();
2020
this.accessTokenString = grantAuthenticationToken.getAccessToken();
21+
this.idTokenString = grantAuthenticationToken.getIdToken();
2122
this.accessTokenHref = grantAuthenticationToken.getAccessTokenHref();
2223
this.tokenType = grantAuthenticationToken.getTokenType();
2324
this.expiresIn = Integer.parseInt(grantAuthenticationToken.getExpiresIn());

impl/src/main/java/com/stormpath/sdk/impl/oauth/DefaultOAuthGrantRequestAuthenticationResult.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
package com.stormpath.sdk.impl.oauth;
1717

1818
import com.stormpath.sdk.lang.Classes;
19-
import com.stormpath.sdk.oauth.*;
19+
import com.stormpath.sdk.oauth.AccessToken;
20+
import com.stormpath.sdk.oauth.OAuthGrantRequestAuthenticationResult;
21+
import com.stormpath.sdk.oauth.RefreshToken;
2022

2123
/**
2224
* @since 1.0.RC7
@@ -27,6 +29,8 @@ public class DefaultOAuthGrantRequestAuthenticationResult implements OAuthGrantR
2729

2830
private final String accessTokenString;
2931

32+
private final String idTokenString;
33+
3034
private final RefreshToken refreshToken;
3135

3236
private final String refreshTokenString;
@@ -40,6 +44,7 @@ public class DefaultOAuthGrantRequestAuthenticationResult implements OAuthGrantR
4044
public DefaultOAuthGrantRequestAuthenticationResult(DefaultOAuthGrantRequestAuthenticationResultBuilder builder) {
4145
this.accessToken = builder.getAccessToken();
4246
this.accessTokenString = builder.getAccessTokenString();
47+
this.idTokenString = builder.getIdTokenString();
4348
this.refreshToken = builder.getRefreshToken();
4449
this.refreshTokenString = builder.getRefreshTokenString();
4550
this.accessTokenHref = builder.getAccessTokenHref();
@@ -51,6 +56,11 @@ public AccessToken getAccessToken() {
5156
return accessToken;
5257
}
5358

59+
@Override
60+
public String getIdTokenString() {
61+
return idTokenString;
62+
}
63+
5464
public String getRefreshTokenString() {
5565
return refreshTokenString;
5666
}

impl/src/main/java/com/stormpath/sdk/impl/oauth/DefaultOAuthGrantRequestAuthenticationResultBuilder.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public class DefaultOAuthGrantRequestAuthenticationResultBuilder implements OAut
3333

3434
protected String refreshTokenString;
3535

36+
protected String idTokenString;
37+
3638
protected String accessTokenHref;
3739

3840
protected String tokenType;
@@ -54,6 +56,10 @@ public String getAccessTokenString() {
5456
return accessTokenString;
5557
}
5658

59+
public String getIdTokenString() {
60+
return idTokenString;
61+
}
62+
5763
public RefreshToken getRefreshToken() {
5864
return refreshToken;
5965
}
@@ -80,6 +86,7 @@ public DefaultOAuthGrantRequestAuthenticationResult build() {
8086

8187
this.accessToken = grantAuthenticationToken.getAsAccessToken();
8288
this.accessTokenString = grantAuthenticationToken.getAccessToken();
89+
this.idTokenString = grantAuthenticationToken.getIdToken();
8390
this.refreshTokenString = grantAuthenticationToken.getRefreshToken();
8491
this.accessTokenHref = grantAuthenticationToken.getAccessTokenHref();
8592
this.tokenType = grantAuthenticationToken.getTokenType();

impl/src/test/groovy/com/stormpath/sdk/impl/oauth/DefaultGrantAuthenticationTokenTest.groovy

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
package com.stormpath.sdk.impl.oauth
1717

1818
import com.stormpath.sdk.impl.ds.InternalDataStore
19-
import com.stormpath.sdk.impl.resource.DateProperty
2019
import com.stormpath.sdk.impl.resource.StringProperty
2120
import org.testng.annotations.Test
2221

23-
import static org.easymock.EasyMock.*
24-
import static org.testng.Assert.*
22+
import static org.easymock.EasyMock.createStrictMock
23+
import static org.testng.Assert.assertEquals
24+
import static org.testng.Assert.assertTrue
2525

2626
/**
2727
* Test for DefaultGrantAuthenticationToken class
@@ -36,10 +36,11 @@ class DefaultGrantAuthenticationTokenTest {
3636

3737
def propertyDescriptors = defaultGrantAuthenticationToken.getPropertyDescriptors()
3838

39-
assertEquals(propertyDescriptors.size(), 5)
39+
assertEquals(propertyDescriptors.size(), 6)
4040

4141
assertTrue(propertyDescriptors.get("access_token") instanceof StringProperty)
4242
assertTrue(propertyDescriptors.get("refresh_token") instanceof StringProperty)
43+
assertTrue(propertyDescriptors.get("id_token") instanceof StringProperty)
4344
assertTrue(propertyDescriptors.get("token_type") instanceof StringProperty)
4445
assertTrue(propertyDescriptors.get("expires_in") instanceof StringProperty)
4546
assertTrue(propertyDescriptors.get("stormpath_access_token_href") instanceof StringProperty)
@@ -51,6 +52,7 @@ class DefaultGrantAuthenticationTokenTest {
5152
def properties = [
5253
access_token: "32J45K565JK3N4K5JN3K4QVMwOFFIRlhNTzdGNTY4Ukc2IiwiYWxnIjoiSFMyNT",
5354
refresh_token: "eyJraWQiOiI2UDVKTjRTQVMwOFFIRlhNTzdGNTY4Ukc2IiwiYWxnIjoiSFMyNT",
55+
id_token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9",
5456
token_type: "Bearer",
5557
stormpath_access_token_href: "https://api.stormpath.com/v1/accessTokens/5hFj6FUwNb28OQrp93phPP",
5658
expires_in: "3600",
@@ -61,6 +63,7 @@ class DefaultGrantAuthenticationTokenTest {
6163

6264
assertEquals(defaultGrantAuthenticationToken.getAccessToken(), properties.access_token)
6365
assertEquals(defaultGrantAuthenticationToken.getRefreshToken(), properties.refresh_token)
66+
assertEquals(defaultGrantAuthenticationToken.getIdToken(), properties.id_token)
6467
assertEquals(defaultGrantAuthenticationToken.getExpiresIn(), properties.expires_in)
6568
assertEquals(defaultGrantAuthenticationToken.getTokenType(), properties.token_type)
6669
assertEquals(defaultGrantAuthenticationToken.getAccessTokenHref(), properties.stormpath_access_token_href)

0 commit comments

Comments
 (0)