Automatically Update Access Token #916

ahmetkarakaya opened this Issue Jan 10, 2017 · 6 comments


None yet

2 participants

ahmetkarakaya commented Jan 10, 2017 edited

After authenticated I use access until it expires, but when it is expired it does not updated automcatically,
Do I need to check Access() is expired or not manually inside an other thread?

		os = OSFactory.builder().endpoint("http://" + ip + ":5000/v2.0")
			.credentials("testtimsoperator", "123456")
			.perspective(Facing.ADMIN)	//Container oluşturmak için
			//.scopeToProject(projectIdentifier, domainIdentifier)  V3 ile gelen bir özellik.			


long delay = os.getAccess().getToken().getExpires().getTime() - System.currentTimeMillis();


User user = findUserByName("user1");
User user2 = findUserByName("user2");


auhlig commented Jan 12, 2017

Hi @ahmetkarakaya
Reauthentication should be triggered in case the code of the response is 401.
Could you check that's the case?

ahmetkarakaya commented Jan 13, 2017 edited

@auhlig yes reauthentication is triggered but newly taken token is only used by one request. For other request to be invoked, same steps are repeated.
I mean first token is used then having 401 error then taken new token to retry the request, I have updated my question by adding sample code portion. As you can see than I have added a delay to expire the token , after then invoking findUserByName() method , I am getting 401 so getting a new token then retring the request.
The problem is when I was invoking findUserByName("user2") I was expecting previous token would be used but I got 401 error then getting a new token . I have analyzed debug logs,

auhlig commented Jan 14, 2017 edited

Understood. Renewed token only used for request. Original token still assigned to session.

Here we check if the response code is 401, in which case the we trigger re-authentication in ll. 64 and assign the new access to the current request .

The authentication-method should also assign the new access to the current session .
Maybe it fails here somewhere.

Would you like to contribute and look into that? I would support.

ahmetkarakaya commented Jan 15, 2017 edited

I have found my faulth that I am always invoking "OSFactory.clientFromAccess(access);" before calling a request and using the same access token.
When I have used OSClient directly instead of OSFactory.clientFromAccess(os.getAccess(), Facing.ADMIN),
I see reauthentication is invoked successfully and newly token is used next request until it expires.

But I am trying to find a solution to a case that
How can I use a single os client with different facing, I need such a case that there many rest requests in a method AllinOneMethod(), some of which must be invoked by ADMIN facing some of which are invokde by null FACING.

auhlig commented Jan 15, 2017

No bug then 😅
Threading maybe. Can we close the issue, since there seems to be no bug? Maybe the google group or stackoverflow community can be of help.



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment