-
Notifications
You must be signed in to change notification settings - Fork 9
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
Notify on logout #122
Notify on logout #122
Changes from 8 commits
d93431b
71cd777
41608fc
725a905
0016784
abd23c1
967b3de
849225b
b94bfa8
5be0268
501d43c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,8 @@ | |
import io.jsonwebtoken.IncorrectClaimException; | ||
import io.jsonwebtoken.Jwts; | ||
import io.jsonwebtoken.SignatureException; | ||
import okhttp3.MediaType; | ||
import okhttp3.RequestBody; | ||
|
||
public class TokenManager { | ||
|
||
|
@@ -75,6 +77,12 @@ public class TokenManager { | |
private final static String ERROR_DESCRIPTION = "error_description"; | ||
private final static String ERROR = "error"; | ||
private final static String INVALID_GRANT = "invalid_grant"; | ||
|
||
private static final String OAUTH_ACTIVITY_LOGGING_PATH = "/activity_logging"; | ||
private static final String ID_KEY = "id_token"; | ||
private static final String ACTIVITY_KEY = "eventName"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we name it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed to EVENT_NAME_KEY, ID_TOKEN_KEY |
||
private static final String LOGOUT_ACTIVITY = "logout"; | ||
|
||
protected enum TOKENS { | ||
ACCESS_TOKEN("access_token"), | ||
ID_TOKEN("id_token"), | ||
|
@@ -352,6 +360,45 @@ protected boolean verifyToken(Key rsaPublicKey, String token, String issuer, Str | |
} | ||
} | ||
|
||
private void sendLoggingRequest(AccessToken accessToken, IdentityToken idToken, String activity) | ||
{ | ||
if (accessToken == null || idToken == null) { | ||
logger.debug("No tokens found for sending logging request"); | ||
return; | ||
} | ||
|
||
RequestBody requestBody; | ||
try { | ||
JSONObject json = new JSONObject(); | ||
json.put(ACTIVITY_KEY, activity); | ||
json.put(ID_KEY, idToken.getRaw()); | ||
requestBody = RequestBody.create(MediaType.parse("application/json"), json.toString()); | ||
} | ||
catch (JSONException err) { // shouldn't happen | ||
logger.debug("Failed to create logging request"); | ||
return; | ||
} | ||
|
||
String url = Config.getOAuthServerUrl(appId) + OAUTH_ACTIVITY_LOGGING_PATH; | ||
|
||
AppIDRequest request = new AppIDRequest(url, "POST"); | ||
|
||
ResponseListener resListener = new ResponseListener() { | ||
@Override | ||
public void onSuccess(Response response) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add info log on success There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. already done |
||
} | ||
@Override | ||
public void onFailure(Response response, Throwable t, JSONObject extendedInfo) { | ||
logger.debug("Failed to submit logging request"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should it be debug ? why not error? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
} | ||
}; | ||
request.send (resListener, requestBody, accessToken); | ||
} | ||
|
||
public void notifyLogout(/*ResponseListener listener*/) { | ||
sendLoggingRequest(latestAccessToken, latestIdentityToken, LOGOUT_ACTIVITY); | ||
} | ||
|
||
public AccessToken getLatestAccessToken () { | ||
return latestAccessToken; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
retrieve back the 3.1.2 v
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you check that v 3.1.2 works for you? It did not work for me and for Vitali. The continuous build also failed.