-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Retrying Eve SSO (RetryingOAuth) using Refresh Token #116
Comments
Also note the last sentence as of https://docs.esi.evetech.net/docs/sso/refreshing_access_tokens.html#sso-response:
As far as I can see, there is no logic in place, which would update the refresh token. |
I hope this is helpful, it's really hard to know what is wrong, when you're not showing your code. |
Thanks! I will check your suggestions and will come back. |
So, I made two mistakes:
I think it's parameter is actually for the accessToken (not refreshToken)
Actually, you always need to use |
I am trying to get all the implications of your statements, but I somehow fail to knot your statements together in my brain. Lemme go through your statements:
I think so, too: The
Okay, that is feasible for me.
That is not the big problem: I have a single known user (whose username and password for login is statically known - if that would help). I need to regularly poll the content of an authentication-enabled endpoint. That user is specially set up for this, btw.
That is perhaps the thing which I don't understand properly:
is the only place where the refreshToken is being adjusted (after running through an authentication flow). However, I don't see any chance that once accountData to invalidate it and have the refreshToken updated.
My understanding was that the
Well, as far as I can see, that's the current refreshToken token:
which calls
That never updates the refreshToken.
Well, in case thanks for your assistance! I need to call an authentication-enabled endpoint periodically. I have a special user set up which has the necessary authorities. The username and password of that user is known statically (i.e.through configuration at command line).
I fetched the refreshToken and created a new ApiClient instance using the builder:
As long as the accessToken is fine, everything works. If either the accessToken is expired or you leave off the The current approach that I am following now is the following:
OAuth authentication = (OAuth) this.delegate.getAuthentication("evesso");
String refreshToken = authentication.getRefreshToken();
OkHttpClient client = new OkHttpClient.Builder().build();
OAuthClient oAuthClient = new OAuthClient(new OAuthOkHttpClient(client));
TokenRequestBuilder tokenRequestBuilder = new OAuthClientRequest.TokenRequestBuilder(
"https://login.eveonline.com/v2/oauth/token").setGrantType(GrantType.REFRESH_TOKEN)
.setClientId(clientid).setClientSecret(clientsecret).setRefreshToken(refreshToken);
OAuthJSONAccessTokenResponse accessTokenResponse = null;
try {
accessTokenResponse = oAuthClient.accessToken(tokenRequestBuilder.buildBodyMessage());
} catch (OAuthSystemException e) {
logger.error("Unable to retrieve new access token by refresh token", e);
throw new ApiException(e);
} catch (OAuthProblemException e) {
logger.error("Error in oAuth infrastructure", e);
throw new ApiException(e);
}
// ...
final String newAccessToken = accessTokenResponse.getAccessToken();
// warning: Also refreshToken must be replaced! See also last sentence of
// https://docs.esi.evetech.net/docs/sso/refreshing_access_tokens.html#sso-response
final String newRefreshToken = accessTokenResponse.getRefreshToken();
authentication.setAuth(clientid, newRefreshToken);
authentication.setAccessToken(newAccessToken);
// ... By this I enforce that the refreshToken gets updated periodically. The problem at mine is:
My gut-feeling currently tells me that a) this is way too complicated how I do it right now, and b) I don't really understand the |
Your problem is that you're mixing two systems. If you want to let eve-esi handle it: If you want to handle it yourself: That is it. |
Made a quick example you can try and run: public static void walletUpdate(String clientId, String refreshToken) throws ApiException {
//The ApiClient can be reused for this refreshToken and is thread safe
ApiClient apiClient = new ApiClientBuilder().clientID(clientId).refreshToken(refreshToken).build();
//Get the characterId
final SsoApi api = new SsoApi(apiClient); //It's important to parse the ApiClient to SsoApi
CharacterInfo info = api.getCharacterInfo();
int characterId = info.getCharacterID();
WalletApi walletApi = new WalletApi(apiClient); //Again, parsing the ApiClient to WalletApi
//Update from ESI
final Double walletBallance = walletApi.getCharactersCharacterIdWallet(characterId, "tranquility", null, null);
} |
It's also worth see the example of how to get an refresh token, if you want to completely switch to using eve-esi: |
Thanks for your suggestions! I have changed the logic to go along the lines of your proposal. Based on previous experience, I still have some doubts, but I want to give it an honest try. Over the night, a long-term standard-test is performed in the background - I would be more than happy, if that showed that my problem was solved with this. |
Your proposal turns out to be very robust (i.e. making eve-esi handling refresh management). The only thing which is very important is that you run at least one call to the token refresh endpoint of the EVESSO-generated refresh token. The refresh token provided there seems to be much more durable and sustainable than the "temporary" refresh token, the EVESSO generated initially. As suggestion for improvement: If I hadn't ask, I would not have seen how I could have got to this information. I'd suggest to write this somewhere into some more detailed documentation (which I might have missed yet?!). This issue here could be used as a reminder/anchor for that. If you don't want to take it up, we can also close this issue here. |
I have the situation that I am fetching an accessToken and a refreshToken through EveSSO. The point is that I have to persist the refreshToken (I am taking care of encryption at rest), because the authentication provided should be retained over multiple executions of the application.
As adviced on the main
README.md
, I was bootstrapping the ApiClient withHowever, when performing the next call for which ESI requires authentication, I get back an unauthorized.
A little debugging showed me that only an instance of OAuth
and not an instance of
RetryingOAuth
is created. Apparently, this leads to the effect that theAuthorization
header is filled with aBearer null
value.I also tried to manually configure the ApiClient instance manually, making sure that a constructor is being called which creates an
Authentication
of typeRetryingOAuth
. However, also there, no avail: I could not get it running. There, theAuthorization
header isn't filled at all - and a break point in methodretryingIntercept
ofRetryingOAuth
is never hit.What am I doing wrong?
The text was updated successfully, but these errors were encountered: