Skip to content
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

Merged
merged 11 commits into from
Nov 14, 2018
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
buildscript {
repositories {
jcenter()
// google()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath "com.android.tools.build:gradle:3.1.1"
Copy link
Contributor

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

Copy link
Contributor Author

@yigal-dayan2 yigal-dayan2 Nov 14, 2018

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.

// classpath 'com.android.tools.build:gradle:3.1.2'
classpath "org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.7.1"
// classpath 'org.robolectric:robolectric-gradle-plugin:1.1.0'
// classpath 'org.jacoco:org.jacoco.core:0.7.8'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,12 @@ public AppIdentity getAppIdentity () {
* log out
* @param context
* @param listener
* currently just call to clearAuthorizationData()
*/
@Override
public void logout (Context context, ResponseListener listener) {
logger.debug("logout");
oAuthManager.getTokenManager().notifyLogout(/*listener*/);
clearAuthorizationData();
// TODO: implement logout
}

public AccessToken getAccessToken () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we name it
EVENT_NAME and
ID_TOKEN ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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"),
Expand Down Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add info log on success

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it be debug ? why not error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;
}
Expand Down