Giter Club home page Giter Club logo

jwtdecode.android's Introduction

Note As part of our ongoing commitment to best security practices, we have rotated the signing keys used to sign previous releases of this SDK. As a result, new patch builds have been released using the new signing key. Please upgrade at your earliest convenience.

While this change won't affect most developers, if you have implemented a dependency signature validation step in your build process, you may notice a warning that past releases can't be verified. This is expected, and a result of the key rotation process. Updating to the latest version will resolve this for you.

JWTDecode.Android

CircleCI Maven Central codecov javadoc

📚 Documentation • 🚀 Getting Started • 💬 Feedback

Documentation

Getting Started

Installation

The library is be available both in Maven Central and JCenter. To start using it add this line to your build.gradle dependencies file:

implementation 'com.auth0.android:jwtdecode:2.0.2'

Usage

Decode a JWT token

String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ";
JWT jwt = new JWT(token);

String issuer = jwt.getIssuer(); //get registered claims
String claim = jwt.getClaim("isAdmin").asString(); //get custom claims
boolean isExpired = jwt.isExpired(10); // Do time validation with 10 seconds leeway

A DecodeException will raise with a detailed message if the token has:

  • An invalid part count.
  • A part not encoded as Base64 + UTF-8.
  • A Header or Payload without a valid JSON format.

Checkout EXAMPLES for more details on how to use the library

Feedback

Contributing

We appreciate feedback and contribution to this repo! Before you get started, please see the following:

Raise an issue

To provide feedback or report a bug, please raise an issue on our issue tracker.

Vulnerability Reporting

Please do not report security vulnerabilities on the public Github issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.


Auth0 Logo

Auth0 is an easy to implement, adaptable authentication and authorization platform. To learn more checkout Why Auth0?

This project is licensed under the MIT license. See the LICENSE file for more info.

jwtdecode.android's People

Contributors

arpit-jn avatar damieng avatar evansims avatar fossabot avatar frederikprijck avatar hzalaz avatar jimmyjames avatar joshcanhelp avatar lbalmaceda avatar oliverspryn avatar poovamraj avatar sabinbajracharya avatar sre-57-opslevel[bot] avatar stevenwong-okta avatar thatfiredev avatar widcket avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jwtdecode.android's Issues

Change MIT license url to SPDX url

Checklist

  • I have looked into the Readme and Examples, and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Describe the problem you'd like to have solved

The license today points to https://raw.githubusercontent.com/auth0/jwtdecode.android/master/LICENSE I would like to suggest to change url to the well known https://spdx.org/licenses/MIT.html url.

This make tools like cashapp's licensee gradle plugin to recognice what license that is being used.

Describe the ideal solution

Change URL to license file

Alternatives and current workarounds

Manually configure the current url as allowed license

licensee {
    allowUrl("https://raw.githubusercontent.com/auth0/jwtdecode.android/master/LICENSE") // MIT License
}

Additional context

No response

Include proguard consumer directives for R8 compatibility

Checklist

  • I have looked into the Readme and Examples, and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Describe the problem you'd like to have solved

Developers using R8 have encountered minification issues with the use of GSON in JWTDecode.Android - #49

Describe the ideal solution

JWTDecode.Android can include proguard directives in a consumer configuration file, which will advertise the issue and solve it for most consumers of the library.

In a new consumer proguard config, include the GSON proguard rules for R8 compiled projects.

https://github.com/google/gson/blob/f72824e2e4d0b719331a040a945876145b7c5acc/examples/android-proguard-example/proguard.cfg#L28

Alternatives and current workarounds

Current workaround is for the consuming project to include the proguard directives for R8 compilers themselves, but that is only likely to happen after they discover the issue, research and locate the solution.

Additional context

Users will discover the issue via a crash report in their minified release builds similar to this:

--------- beginning of crash

2023-08-07 13:47:36.054 16347-17602/? E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
Process: foo_bar, PID: 16347
java.lang.RuntimeException: Missing type parameter.
at com.google.gson.reflect.TypeToken.(SourceFile:10)
at u6.c.(Unknown Source:0)
at com.auth0.android.jwt.JWT.(SourceFile:6)
at v6.i.c(SourceFile:3)
at v6.i$b.onSuccess(SourceFile:2)
at v6.o$a.onSuccess(SourceFile:2)
at w6.g.onResponse(SourceFile:7)
at com.squareup.okhttp.Call$b.execute(SourceFile:6)
at com.squareup.okhttp.internal.NamedRunnable.run(SourceFile:3)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)

Gson R8 proguard rules (java.lang.runtimeexception: missing type parameter.)

Checklist

  • I have looked into the Readme and Examples, and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Description

I was using val jwt = JWT(tokenId) to retrieve claims from the tokenId, in the release build of my android studio project, along with R8 enabled. However I've received the following error: java.lang.runtimeexception: missing type parameter.

After adding those three lines of code in the proguard-rules.pro, the error disappeared:

-keep class com.google.gson.reflect.TypeToken
-keep class * extends com.google.gson.reflect.TypeToken
-keep public class * implements java.lang.reflect.Type

I also had to manually add Gson library to my project just to add those rules, since I'm using KotlinX Serialization library.
Is there a way for you to add those rules for Gson, when using R8, so that we don't have to?

Reproduction

  1. Enable R8
  2. Retrieve claims from a tokenId with val jwt = JWT(tokenId)

Additional context

No response

JWTDecode.Android version

2.0.2

Android version(s)

33

Contribution Guide

Hello, I ran into a problem using this library with out Auth0 implementation. I believe the work around would be pretty easy and I wouldn't mind contributing to this project with a pull request. However, I'm having trouble building the project locally as it seems to rely on a plugin that is only available in a private Bintray repo. Do you have any sort of contribution guide?

Specifically, what I'm trying to do is related to #21 . We're sending some custom JSON in our tokens and I need to get them out. none of the ClaimImpl methods work for me. I was thinking that if I could simply get out the raw value from the Claim that I could handle parsing the JSON myself.

Getting object list for a claim

I'm currently using the library in my android app for receiving a token with a claim called "realm_access", but i can't get the list of strings inside him.

"realm_access": {
"roles": [
"role-one",
"role-two"
]
},

Kotlin Multiplatform Implementation

Checklist

  • I have looked into the Readme and Examples, and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Describe the problem you'd like to have solved

Hello all,
this library currently won't work with kotlin multiplatform module because it's using the:

Example implementation in my code (splitToken is copied from this project)

val jwtBody = JWTPayload.splitToken(loginData.access_token ?: "")?.get(1)
if (jwtBody.isNullOrEmpty()) {
    throw IllegalArgumentException()
}
val jwtAccessToken = Json{ ignoreUnknownKeys = true }.decodeFromString<JWTPayload>(
    jwtBody.decodeBase64Bytes().decodeToString()
)
if (jwtAccessToken.sub.isEmpty()) {
    throw IllegalArgumentException()
}

Regards,
Luca.

Describe the ideal solution

Replace base64 and parcelable function/object.

Alternatives and current workarounds

Implement native code functions/libs.

Additional context

No response

Pro-guard Issue

I'm not able to extract data when I enable minifyEnabled true in release build, instead it's working perfectly in debug mode.

getClaim return null

Hi maintainers anyone can help me. We use the next token, but when use getClaim function the value return is null. We use a debugger to explain what happens, it has a full payload, but return null after getAsString.

String token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhbGxvd2VkU2VydmljZXMiOlsiYXBpLXVzdWFyaW9zLTEyM3Bvcm1pIiwiYmVuZWZpY2lvcyJdLCJwYXlsb2FkIjp7ImlkIjoyMSwibmFtZSI6IkJyZW5kYSIsImZpcnN0U3VybmFtZSI6IkRvbcOtbmd1ZXoiLCJzZWNvbmRTdXJuYW1lIjoiR8OhbWV6IiwiZW1wbG95ZWVJZCI6MzEyNX0sImlhdCI6MTU2ODg1MjIwNywiZXhwIjoxNTY4ODUyODA3fQ.VCvXEAXWUheHd4JCp-QxRr0AADn_akQGMAsok4WY19Jo74LdFYpgx7N-fBs4qGlJ3cIurUkyUOOCc8F_XXjdt5qTOx2Y2GHYgsrOD5Jwx9ZJ-F7GBmq1aY6ubRDBCTKnlJnunIsF-r4Cdp1qJy6Ygaag_G8fWGYdGNFS4De53tm8WMTi2IFeO_AitRSJbrqG8YWyFe1T4UQXTuv8NTJ9WkZFbcQwJMtYAGbltY5FxhFL3ReL7dVGb-rxMCnBEFs-IPOu4Or6K0vOaXXaxl7TRJV2OU2Xh1ulLbosG09Wce0jHn18Rw22K1wanF71H1nv8bwmJsQB5meWykevRi3T3g";

JWT jwt = new JWT(token);
String name = jwt.getClaim("name").asString();

jwt.getExpiresAt().getTime() adds some zero that poison the exp field

I'm using your lib on my app and I was stuck until I found this bug because my server says that token has expired but inside the app the case of an expired token is prevented.

So here is what happens all time: when I retrieve my jwt from the server I pass inside my shared preferences'handler the token as a string with this function:

private void setNewSession(String token, boolean firstLogin) {
        editor.putBoolean(IS_LOGIN, true);
        JWT jwt = new JWT(token);
        editor.putString(KEY_USER_TOKEN, token);
        editor.putLong(KEY_DEADLINE, jwt.getExpiresAt().getTime());
        editor.putBoolean(KEY_FIRST_LOGIN, firstLogin);
        editor.apply();
        if(DEBUG) {
            Log.d(TAG_USER_CLASS,"Token: "+ jwt);
            Log.d(TAG_USER_CLASS,"Data di scadenza del token in ms : "+ jwt.getExpiresAt().getTime());
            Log.d(TAG_USER_CLASS,"Data di scadenza del token: "+ DateFormat.getDateTimeInstance().format(jwt.getExpiresAt()));
        }
    }

The problem is with the method: jwt.getExpiresAt().getTime() because instaed of returning the correct time it returns the correct time as long + 000.
Here is an example of the token passed by the server and the return of the method:
cattura

This is the result it should appear, I've calculated using the same token and the jwt debugger on site:

  • token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI1YTRmYTdlODUwNTdjNDU1NjRiZGIwNmMiLCJleHAiOjE1MTc0NDM3NDY4MzZ9.----OMITTEDKEYPART----

  • "exp": 1517443746836

And as you can note that your library output (1517443746836000) is different from the site output (1517443746836).

Please let me know if you have the same issue that I have and hope you'll solve as soon as possible.

DecodeException when header contains array?

Checklist

  • I have looked into the Readme and Examples, and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Description

eyJhbGciOiJSUzI1NiIsIng1YyI6WyJNSUlGYnpDQ0JGZWdBd0lCQWdJUkFLZGZxUmlyMjF1ZUNpWXloVFIxcS9Zd0RRWUpLb1pJaHZjTkFRRUxCUUF3UmpFTE1Ba0dBMVVFQmhNQ1ZWTXhJakFnQmdOVkJBb1RHVWR2YjJkc1pTQlVjblZ6ZENCVFpYSjJhV05sY3lCTVRFTXhFekFSQmdOVkJBTVRDa2RVVXlCRFFTQXhSRFF3SGhjTk1qUXdNVEk1TURrd09USTJXaGNOTWpRd05ESTRNRGt3T1RJMVdqQWRNUnN3R1FZRFZRUURFeEpoZEhSbGMzUXVZVzVrY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mthcHBzLnNhZnRleW5ldCIsImFwa0RpZ2VzdFNoYTI1NiI6IkpKdHlkZjVyblJ4YytTK1ZrSENBUVdKWVFxcDliL0FkYklhVjlZckRDcnM9IiwiY3RzUHJvZmlsZU1hdGNoIjpmYWxzZSwiYXBrQ2VydGlmaWNhdGVEaWdlc3RTaGEyNTYiOlsiRDN6MjZ3S1doL2RTTkdsczJqQU14MTFNa2YwOWVVcUFPWmFhM2xXKzVBMD0iXSwiYmFzaWNJbnRlZ3JpdHkiOnRydWUsImV2YWx1YXRpb25UeXBlIjoiQkFTSUMiLCJkZXByZWNhdGlvbkluZm9ybWF0aW9uIjoiVGhlIGFwcCBpcyBhbGxvd2xpc3RlZCB0byB1c2UgdGhlIFNhZmV0eU5ldCBBdHRlc3RhdGlvbiBBUEkgdW50aWwgdGhlIGZ1bGwgdHVybmRvd246IGh0dHBzOi8vZy5jby9wbGF5L3NhZmV0eW5ldC10aW1lbGluZS4ifQ.c7TsHcXTfFO57j9eQOPRNEMqab-YG-FLEZOQyPNZEg2rYHbjyqK46uU5x5ePbzXgYR0gh_gifoaySizVjzL-pl8CVz4FSdJ7aeSkQ4BYtV3kFprPiGormMU5Ze7tF39PwLvUDZoEzB7mev_LI73rZEcsF-_qdPeeOYWbozXRc_KF8knw5uLWaQfmFE_sHxa_7hIlmnLb-PGrWM_7X1tn9JfVrAToiRcKyyuXlo5OsfRVlodgmBupxgV5EDpxZ1PzgISph1HJE237-LTSmsDz0Yq94zekucfUbRwgOPR6XrPEDBWllKWTUQu7ffizgRHDtqwusgT3vWAIfpgpA__Gvg

this jwt token cuz it!

Reproduction

JWT jwt = new JWT(jwsResult);            

Caused by: com.auth0.android.jwt.DecodeException: The token's payload had an invalid JSON format.
at com.auth0.android.jwt.JWT.parseJson(JWT.java:247)
at com.auth0.android.jwt.JWT.decode(JWT.java:213)
at com.auth0.android.jwt.JWT.(JWT.java:40)

Additional context

No response

JWTDecode.Android version

2.0.2

Android version(s)

13

jwt.getClaims().get("referCode").asString() returns null even if present

Checklist

  • I have looked into the Readme and Examples, and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Description

Hi, can anyone help me with this? I'm trying to extract the data from the JWT token using JWTDecode. When I debug, I get the values but when I use them I get null.

Reproduction

String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InZhaWJoYXYubWFuZGxpazFAZ21haWwuY29tIiwiaWQiOjEsImNhdGVnb3J5IjoiMSIsImVtYWlsIjoidmFpYmhhdi5tYW5kbGlrMkBnbWFpbC5jb20iLCJyZWZlckNvZGUiOiJWVFlKSCIsImlhdCI6MTY4NTg3MTkxNSwiZXhwIjoxNjg1ODc1NTE1fQ.XPKYs9mhS3pgF13a5PDek0EhM_izfg1gP0aCxyxdWAI";

JSONObject jsonObject = new JSONObject(userData); JWT jwt = new JWT(jsonObject.getString("token")); if (jwt.getClaims().containsKey("referCode")) { TextView referCode = dialog.findViewById(R.id.refer_code); referCode.setText(jwt.getClaims().get("referCode").asString()); }

Additional context

No response

JWTDecode.Android version

2.0.2

Android version(s)

13

null "sub" claim throws an exception

As per the jwt spec, the recommended claims such as "sub" are not mandatory.
Due to certain business requirements, I have to construct a "temporary" JWT which has "sub" as null.

The library throws an exception on android.

Issue: Getting nested object claim values list

Hi, I’m currently using the library in my android app for receiving a token with a claim called “user_claim” that contains a list of parameters, the decode works fine because I can see the values while debugging but when I use one of the methods asList, asArray, asString to get values of the claim, returns null or an empty list or array, I’m using Java 8 in Android Studio 3.0.1 and jwtdecode:1.1.1, I’m not sure if something is missing, also here is a fragment of my code in case something is missing in my implementation you can tell me:

JWT jwtToken = new JWT(token);
Claim userClaim = jwtToken.getClaim("user_claims");
ArrayList<String> list = new ArrayList<>(userClaim.asList(String.class));

Best
Luis

Invalid JSON Format Exception

I have an example JWT in this format:

eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiZmIxNTQ5YmYtMWNmYi00ZjhiLTkxODgtZjZiMTgzYmVmOGFiIiwiZXhwIjoxNTIwNTUzMDQ5LCJpYXQiOiIyMDE4LTAyLTA4IDIzOjUwOjQ5IFVUQyJ9.EfkRQhLKelDXX6XPbA7wVug9k90wioHBhEc1vA07OAA

When I run this through new JWT();, I get an exception claiming some sort of invalid JSON formatting. I've looked at the Base64 decode of this string, and it looks valid too me, but the payload section is triggering an exception. What is wrong with this token? Is the lack of signature causing this issue?

Urgent :: Not Getting Decode JWT to Json

Description

I m decoding token to json but i m not getting it.

Environment

Please provide the following:

  • Version of JWTDecode.Android used: latest
  • Version of Android used:8.0
  • Additional libraries that might be affecting your instance:

Reproduction

Detail the steps taken to reproduce this error and note if this issue can be reproduced consistently or if it is intermittent.

Please include:

Token :: eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IlFqZEdORGcyUlRVM01EYzNPVFpGTVVJNU5EZzRPVFEwUXpoRk5VSXdRek14TURBM1JqQTJNZyJ9.eyJodHRwczovL2NvaGVzaW9uaWIuY29tL2licF9idWlsZGluZ0NvZGUiOiJKSVJBMDAxIiwiaHR0cHM6Ly9jb2hlc2lvbmliLmNvbS9pYnBfY29tcGFueUNvZGUiOiJBMTA1IiwiaHR0cHM6Ly9jb2hlc2lvbmliLmNvbS9pYnBfdXNlcklkIjoiYjMwMjM2MjMtZWFjNi00ZDE5LTgyZWUtMDhkNjhiMzk4OWJhIiwiaHR0cHM6Ly9jb2hlc2lvbmliLmNvbS9pYnBfcm9sZXMiOlt7Im1JZCI6MSwidmFsIjowLCJmTGlzdCI6W3siZklkIjoxMDUsInZhbCI6MH0seyJmSWQiOjEwNCwidmFsIjowfV19LHsibUlkIjoyLCJ2YWwiOjAsImZMaXN0IjpbeyJmSWQiOjIwMiwidmFsIjowfSx7ImZJZCI6MjAzLCJ2YWwiOjB9LHsiZklkIjo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CJhdWQiOlsiaHR0cDovLzEwNC4yMTEuMTY3LjY0OjgyLyIsImh0dHBzOi8vY29oZXNpb25pYi5hdXRoMC5jb20vdXNlcmluZm8iXSwiaWF0IjoxNTQ5MzU2NDUxLCJleHAiOjE1NDk0NDI4NTEsImF6cCI6IjRXRTB0OUhsUEpKeTUzN3F1bXEzaU9oRWNuTkJ5MHR0Iiwic2NvcGUiOiJvcGVuaWQgcHJvZmlsZSBlbWFpbCBvZmZsaW5lX2FjY2VzcyJ9.dAtyCS2C_OdvvUHRwMEISOC_jUS4xtfX69wR_o8_yvBa5iCoitayb9LMcmAtYc6O62dd97lPQhRVbvD0fljpxqjQ3F8Bqk28wrMlJOB7aqSJuugQWE7t-jAKU5yrgOxrPw9HRQ6kiLQpzqAsd9fsoR_bsESb4e8tG1qhvnI6Ign0a3xOMsAmyYr7Pf2wJWbh_H10ibwUD50q-75npC9P88mOv1vZnga0vpW0OqXy3ZaKUGry4dKwhbsHSfm4JsctneewvdVGT2Ky1Hddlvol6t7pENGY1toaAJN_OY57uo-8J4cb7p0WFH84bAN_A0xAQcYmFI1Nc5Aw_115PEq1KA

try {
JWT jwt = new JWT(payload.getAccessToken());

                   Map<String, Claim> allClaims = jwt.getClaims();

                   Claim subscriptionMetaData =  jwt.getClaim("https: //cohesionib.com/ibp_companyCode");
                   String parsedValue = subscriptionMetaData.asString();

                   Log.e("decoded" ,"" +  parsedValue);
                   Log.e("decoded 1 " ,"" +  allClaims);

               } catch (DecodeException exception){
                   //Invalid token
                   Log.e("decoded" ,"" +  exception.getMessage());
               }

All Claim :: {https://cohesionib.com/ibp_companyCode=com.auth0.android.jwt.ClaimImpl@7435f82, sub=com.auth0.android.jwt.ClaimImpl@f557693, aud=com.auth0.android.jwt.ClaimImpl@a3676d0, https://cohesionib.com/ibp_roles=com.auth0.android.jwt.ClaimImpl@64426c9, azp=com.auth0.android.jwt.ClaimImpl@74bf1ce, scope=com.auth0.android.jwt.ClaimImpl@256e8ef, https://cohesionib.com/ibp_buildingCode=com.auth0.android.jwt.ClaimImpl@1d42ffc, iss=com.auth0.android.jwt.ClaimImpl@6df6685, https://cohesionib.com/ibp_userId=com.auth0.android.jwt.ClaimImpl@e395cda, exp=com.auth0.android.jwt.ClaimImpl@353250b, iat=com.auth0.android.jwt.ClaimImpl@1324fe8}

PArticular Claim :: null

Please Help as soon as possible.

GSON unserialization issue

Hello,

When I try

gson.fromJson(jsJWT, JWT.class)

I get an exception:

java.lang.RuntimeException: Unable to invoke no-args constructor for interface com.auth0.android.jwt.Claim. Register an InstanceCreator with Gson for this type may fix this problem.

I use 'com.auth0.android:jwtdecode:1.1.1'

I hope you can help...
Thanks

Problem trying to include dependency to gradle

I am trying to add in dependencies in my project but it is causing error. I know it's not a problem to be questioned here, but someone can help me. What happens is if I add:
All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes).
My gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "25.0.1"
    defaultConfig {
        applicationId "mobitrak.zenitetecnologia.com.br.mobitrak"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.auth0.android:jwtdecode:1.1.1'
    compile 'com.android.support:appcompat-v7:23.2.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha4'
    compile 'com.android.support:design:23.0.1'
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    compile 'com.google.android.gms:play-services:10.0.1'
    compile 'com.google.firebase:firebase-messaging:9.6.1'
    compile 'com.android.support:multidex:1.0.1'

    testCompile 'junit:junit:4.12'
}

apply plugin: 'com.google.gms.google-services'

Feature Request: getAllClaims()

It would be convenient to be able get all claims from JWT's payload. JWTPayload class has a private tree object. Could it be returned, when we'd call getAllClaims() on our token instance?

DecodeException when header contains array

Describe the problem

JWT(accessToken) fails with DecodeException, "The token's payload had an invalid JSON format." when the token header contains anything other than String key/value pairs. Arrays and JSON objects are not supported.

FusionAuth started sending an array as the value in new responses, causing this library to fail. Below is an example token response header which fails:

{
  "alg": "RS512",
  "typ": "JWT",
  "gty": [
    "authorization_code"
  ]
}

The "gty" field can't be parsed because it contains an array.

What was the expected behavior?

This is valid JSON, so this should not fail. I don't believe JWT disallows additional fields.

Reproduction

The problem is JWT only decodes for String values in the header. Something that is seemingly fixed in the Auth0/Android library.

Environment

  • Version of this library used: 2.0.1

isExpired() always returns false

isExpired(leeway) always returns me false
shouldn't it be

        boolean expValid = payload.exp == null || !futureToday.after(payload.exp);
        boolean iatValid = payload.iat == null || !pastToday.before(payload.iat);

instead of

        boolean expValid = payload.exp == null || !pastToday.after(payload.exp);
        boolean iatValid = payload.iat == null || !futureToday.before(payload.iat);

?

How to verify a token on Android

Hi,

In https://github.com/auth0/java-jwt there is a specific section on how to verify a token.

I was wondering if that is possible on the Android side, i.e. if I have the public key and the algorithm, how could we verify that the received token was issued by a valid issuer?

In short, is there any way to verify the issuer of a signed token?

Many thanks in advance,

Manos

Exception thrown when json field null

Describe the problem

An exception is thrown when parsing a JWT with explicit nulls instead of absent fields.

What was the expected behavior?

The JWT token is parsed with null fields

Reproduction

Try parsing

eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOm51bGx9.2zjeZFRPs4sTM9Lmb10uzLOJdWAtlmGUQJByV8o8jZY

this corresponds to:

{
  "iss": null
}

an exception will be thrown, whereas one would not be thrown with:

{}

This exception comes from calling .getAsString() on JsonNull in this method https://github.com/auth0/JWTDecode.Android/blob/master/lib/src/main/java/com/auth0/android/jwt/JWTDeserializer.java#L71.

Perhaps you could change your check to:

if (!obj.has(claimName) || obj.get(claimName).isJsonNull()) {
    return null;
}

When minifyEnabled is set to true, android app crashes moment user logs in. Using different build type than release.

When minifyEnabled is set to true, android app crashes moment user logs in and receives JWT token.
Do we need to add any proguard rules while using this library? Nothing is mentioned in steps so i was wondering.

What was the expected behavior?

User should be able to login with valid token received from server. If i remove minifyEnabled flag it works.

  • Version of the library used : 2.0.0
  • Crash log:
    g.b.a.a.d: The token was expected to have 3 parts, but got 1.
    at g.b.a.a.e.(:6)
    at g.c.a.a.k.b.a(Unknown Source:7)
    at g.c.a.a.i.j.a(:11)
    at g.c.a.a.j.a$b.a(Unknown Source:12)
    at j.l0.g.e$a.run(:6)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:919)

Feature request: without gson

Hi maintainers,

would it be possible to get a version of this library without gson? My current application has no reference to this and I don't want to bloat it. Why not just using pure json.org.
If you would be fine with this, I also could create a PR with these changes.

Best
Hasan

Nullpointer Exception - base64decode()

Description

Getting Nullpointer Exception after calling:

val token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"

val jwt = JWT(token)

This line returns null for string: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"
byte[] bytes = Base64.decode(string, Base64.URL_SAFE | Base64.NO_WRAP | Base64.NO_PADDING);

In Gradle:
implementation 'com.auth0.android:jwtdecode:2.0.0'

Stacktrace:

java.lang.NullPointerException
at java.lang.String.(String.java:515)
at com.auth0.android.jwt.JWT.base64Decode(JWT.java:235)
at com.auth0.android.jwt.JWT.decode(JWT.java:213)
at com.auth0.android.jwt.JWT.(JWT.java:40)
at *.utils.TokenValidator.isTokenValid(TokenValidator.kt:9)
at *.pwa.webview.PWAWebViewModelImpl$onTokenInvalid$1.invoke(PWAWebViewModel.kt:273)
at *.pwa.webview.PWAWebViewModelImpl$onTokenInvalid$1.invoke(PWAWebViewModel.kt:48)
at *.utils.TestPWAModel.onTokenInvalid(MockFactory.kt:218)
at *.webview.PWAWebViewModelImpl.onTokenInvalid(PWAWebViewModel.kt:272)
at *.PWAWebViewModelTest.new token is passed in token invalid callback(PWAWebViewModelTest.kt:426)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.mockito.internal.runners.DefaultInternalRunner$1$1.evaluate(DefaultInternalRunner.java:44)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.mockito.internal.runners.DefaultInternalRunner$1.run(DefaultInternalRunner.java:74)
at org.mockito.internal.runners.DefaultInternalRunner.run(DefaultInternalRunner.java:80)
at org.mockito.internal.runners.StrictRunner.run(StrictRunner.java:39)
at org.mockito.junit.MockitoJUnitRunner.run(MockitoJUnitRunner.java:163)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)

JWT encode for Android?

Someone mentioned that JWT signing on clients does not make much sense because you can't keep the shared secret secret.

I still don't get the complete picture why.
Supposed I have a login screen for my user on a mobile app, and I negotiate the shared secret between clients and servers on each login. I can keep the shared secret in, says, secured storage of the device, can't I?

I don't see which part of it is not feasible.
Can someone explain the lack of an encoding library for mobile devices?
May I add it as a feature request?

com.auth0.android.jwt.DecodeException: The token was expected to have 3 parts, but got 1.

Checklist

  • I have looked into the Readme and Examples, and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Description

Hello,

Recently I found this issue. Sometimes it shows this error but If i decode error token in jwt website it is ok. can you please look into it

com.auth0.android.jwt.DecodeException: The token was expected to have 3 parts, but got 1.

Reproduction

  1. use token to decode.

Additional context

No response

JWTDecode.Android version

2.0.2

Android version(s)

12

Gson dissapears from android project after import JTWDecode

Describe the problem

After insetting

implementation 'com.auth0.android:jwtdecode:2.0.0'

in my app built.gradle I loose all refference to Gson in the rest of my project.

What was the expected behavior?

to keep Gson

Reproduction

    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
    implementation 'com.auth0.android:jwtdecode:2.0.0'

Environment

Android
Groovey
Kotlin

java.lang.ArrayIndexOutOfBoundsException - length=1; index=1

Checklist

  • I have looked into the Readme and Examples, and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Description

Hello,

I am using this library in my android application to decode jwt token but sometimes i am getting this eror (java.lang.ArrayIndexOutOfBoundsException - length=1; index=1) error but token is valid.
How I can solve this issues can you please suggest me.

Reproduction

I can't produce it since my application in play store.

Additional context

No response

JWTDecode.Android version

2.0.2

Android version(s)

13

Getting nested JSON from claim object.

Current api allows only to get primitives from claim. In case claim contains objects they can't be parsed.

Since the library already uses GSON it would be very useful to parse the payload using it, instead of parsing it manually using getBoolean, getInt and so on methods.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.