@@ -27,9 +27,18 @@ import com.stormpath.sdk.application.webconfig.MeConfig
2727import com.stormpath.sdk.application.webconfig.MeExpansionConfig
2828import com.stormpath.sdk.application.webconfig.Oauth2Config
2929import com.stormpath.sdk.application.webconfig.VerifyEmailConfig
30+ import com.stormpath.sdk.cache.Caches
3031import com.stormpath.sdk.client.Client
3132import com.stormpath.sdk.client.ClientIT
33+ import com.stormpath.sdk.client.Clients
3234import com.stormpath.sdk.directory.Directory
35+ import com.stormpath.sdk.oauth.AccessToken
36+ import com.stormpath.sdk.oauth.Authenticators
37+ import com.stormpath.sdk.oauth.OAuthBearerRequestAuthentication
38+ import com.stormpath.sdk.oauth.OAuthPasswordGrantRequestAuthentication
39+ import com.stormpath.sdk.oauth.OAuthRequestAuthenticator
40+ import com.stormpath.sdk.oauth.OAuthRequests
41+ import com.stormpath.sdk.oauth.RefreshToken
3342import org.testng.annotations.Test
3443
3544import static org.testng.Assert.*
@@ -185,6 +194,42 @@ class WebConfigurationIT extends ClientIT {
185194 }
186195 }
187196
197+ @Test
198+ void testGetAccessTokenSignedWithDifferentKey () {
199+
200+ def app = createTempApp()
201+
202+ def account = createTestAccount(app)
203+
204+ OAuthPasswordGrantRequestAuthentication grantRequest = OAuthRequests . OAUTH_PASSWORD_GRANT_REQUEST . builder()
205+ .setLogin(account. email). setPassword(" Changeme1!" ). build()
206+
207+ OAuthRequestAuthenticator authenticator = Authenticators . OAUTH_PASSWORD_GRANT_REQUEST_AUTHENTICATOR . forApplication(app)
208+
209+ def accessTokenResult = authenticator. authenticate(grantRequest)
210+
211+ def webConfigApiKey = app. getWebConfig(). getSigningApiKey()
212+
213+ def client = Clients . builder(). setBaseUrl(baseUrl). setCacheManager(Caches . newDisabledCacheManager()). setApiKey(webConfigApiKey). build()
214+
215+ def newClientApp = client. getResource(app. href, Application )
216+
217+ // Authenticate token against Stormpath
218+ OAuthBearerRequestAuthentication authRequest = OAuthRequests . OAUTH_BEARER_REQUEST . builder(). setJwt(accessTokenResult. getAccessTokenString()). build()
219+ def authResultRemote = Authenticators . OAUTH_BEARER_REQUEST_AUTHENTICATOR . forApplication(newClientApp). authenticate(authRequest)
220+
221+ assertEquals authResultRemote. getApplication(). getHref(), app. href
222+ assertEquals authResultRemote. getAccount(). getHref(), account. href
223+
224+ def accessToken = client. getResource(accessTokenResult. accessTokenHref, AccessToken )
225+
226+ assertNotNull accessToken
227+
228+ def refreshToken = client. getResource(accessTokenResult. refreshToken. href, RefreshToken )
229+
230+ assertNotNull refreshToken
231+ }
232+
188233 ApiKey createTmpApiKey (Application application ) {
189234 def directory = client. instantiate(Directory )
190235 directory. setName(uniquify(" Admins" ))
0 commit comments