Skip to content

Commit

Permalink
Fix bug in jwt generation
Browse files Browse the repository at this point in the history
  • Loading branch information
dimtion committed Mar 25, 2020
1 parent cd36ae5 commit 1bf527f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 3 additions & 3 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
<output-test url="file://$MODULE_DIR$/build/intermediates/javac/debugUnitTest/classes" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/ap_generated_sources/debug/out" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/aidl_source_output_dir/debug/out" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/renderscript_source_output_dir/debug/out" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/renderscript_source_output_dir/debugAndroidTest/out" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/ap_generated_sources/debugAndroidTest/out" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/aidl_source_output_dir/debugAndroidTest/out" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/renderscript_source_output_dir/debugAndroidTest/out" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/ap_generated_sources/debugUnitTest/out" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public boolean isCompatibleShaarli() throws IOException {
return e.getStatusCode() == 401; // API V1 supported
}
} catch (JSONException e) {
Log.w("RestAPINetworkManager", e.toString());
Log.e("RestAPINetworkManager", e.toString());
return false;
}
// assume a 2XX or 3XX means API V1 supported
Expand All @@ -68,11 +68,14 @@ public boolean login() throws IOException {
// TODO: we could set some account parameters from here like default_private_links
String url = new URL(this.mAccount.getUrlShaarli() + INFO_URL).toExternalForm();
try {
Log.d("Login", this.mAccount.getRestAPIKey());
String body = this.newConnection(url, Connection.Method.GET)
.execute()
.body();
Log.i("RestAPINetworkManager", body);
Log.i("Login", body);
} catch (HttpStatusException e) {
Log.w("Login", e);
Log.w("Login", e.getMessage());
return false;
}
return true;
Expand Down Expand Up @@ -207,8 +210,12 @@ public List<String> retrieveTags() throws Exception {
* @return JWT encoded in base 64
*/
String getJwt() {
// The date the token is issued at, will be mapped to the key "iat" in the payload
// iat in the payload
Date date = new Date();
// During debugging I found that given that some servers and phones are not absolutly in sync
// It happens that the token would looked like being generated in the future
// To compensate that we remove 5 from the actual date.
date.setTime(date.getTime() - 5000);
// The key used to sign the token, you can find it by logging to your Shaarli instance
// and then going to "Tools"
byte[] signingKey = this.mAccount.getRestAPIKey().getBytes();
Expand Down

0 comments on commit 1bf527f

Please sign in to comment.