public RTResponse createResponse(AccessToken at, RefreshToken rt){ return new RTResponse(at, rt); } }
/** * This will take the identifier and make the necessary calls to the service to update the refresh * token and access token. This returns the asset or null if no such asset exists. * * @param identifier */ public RTResponse refresh(String identifier) { OA2Asset asset = (OA2Asset) getAssetStore().get(identifier); if (asset == null) return null; DS2 ds2 = (DS2) getEnvironment().getDelegationService(); RTRequest rtRequest = new RTRequest(getEnvironment().getClient(), null); rtRequest.setAccessToken(asset.getAccessToken()); rtRequest.setRefreshToken(asset.getRefreshToken()); RTResponse rtResponse = ds2.refresh(rtRequest); asset.setAccessToken(rtResponse.getAccessToken()); asset.setRefreshToken(rtResponse.getRefreshToken()); getAssetStore().remove(asset.getIdentifier()); // clear out getAssetStore().save(asset); return rtResponse; }
@Override public RTResponse processRTRequest(RTRequest rtRequest) { AccessToken accessToken = rtRequest.getAccessToken(); RefreshToken refreshToken = rtRequest.getRefreshToken(); if (refreshToken == null) { throw new GeneralException("Error: There is no refresh token, so it is not possible to refresh it."); } String raw = getRTResponse(getAddress(), refreshToken, rtRequest.getClient()); JSONObject json = getAndCheckResponse(raw); String returnedAT = json.getString(OA2Constants.ACCESS_TOKEN); if (accessToken.getToken().equals(returnedAT)) { throw new IllegalArgumentException("Error: The returned access token from the server should not match the one in the request."); } String exp = json.getString(OA2Constants.EXPIRES_IN); if (exp == null || exp.length() == 0) { throw new IllegalArgumentException("Error: missing expires_in field from server"); } long expiresIn = Long.parseLong(exp) * 1000; JSONObject claims = getAndCheckIDToken(json, rtRequest); OA2RefreshTokenImpl refreshTokenImpl2 = new OA2RefreshTokenImpl(URI.create(json.getString(OA2Constants.REFRESH_TOKEN))); AccessToken newAT = new AccessTokenImpl(URI.create(returnedAT)); refreshTokenImpl2.setExpiresIn(expiresIn); RTResponse rtResponse = createResponse(newAT, refreshTokenImpl2); rtResponse.setParameters(claims); return rtResponse; }
public void getrt(InputLine inputLine) throws Exception { if (showHelp(inputLine)) { getRTHelp(); return; } RTResponse rtResponse = getOA2S().refresh(dummyAsset.getIdentifier().toString()); dummyAsset = (OA2Asset) getCe().getAssetStore().get(dummyAsset.getIdentifier().toString()); // Have to update the AT reponse here every time or no token state is preserved. currentATResponse = new ATResponse2(dummyAsset.getAccessToken(), dummyAsset.getRefreshToken()); currentATResponse.setParameters(rtResponse.getParameters()); JSONObject json = JSONObject.fromObject(currentATResponse.getParameters()); claims = json; if (inputLine.hasArg(CLAIMS_FLAG)) { if (json.isEmpty()) { say("(no claims found)"); } else { say(json.toString(2)); } } printTokens(); }