我正在使用这样的 JJWT 库生成令牌 -
final String issuer = "my-app-auth-server@my-app-797ab.iam.gserviceaccount.com";
final String sub = "my-app-auth-server@my-app-797ab.iam.gserviceaccount.com";
final String aud = "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit";
final String secret = "my-secret-key" //only demo key , not real secret key that i am using
final long iat = System.currentTimeMillis() / 1000L; // issued at claim
final long exp = iat + 60L; // expires claim. In this case the token expires in 60 seconds
final String jwtString = Jwts.builder()
.claim("alg","HS256")
.claim("iss", issuer)
.claim("aud",aud)
.claim("iat", iat)
.claim("exp", exp)
.claim("uid",number)
.setSubject(sub)
.signWith(SignatureAlgorithm.HS256, secret)
.compact();
我使用的密钥(“my-secret-key”)由 Firebase 生成,如此处所述
但是当我使用上面生成的令牌登录 Firebase 时出现此错误 -
com.google.firebase.auth.FirebaseAuthInvalidCredentialsException: The custom token format is incorrect. Please check the documentation.
at com.google.android.gms.internal.zzafd.zzes(Unknown Source)
at com.google.android.gms.internal.zzafa$zzg.zza(Unknown Source)
at com.google.android.gms.internal.zzafl.zzet(Unknown Source)
at com.google.android.gms.internal.zzafl$zza.onFailure(Unknown Source)
at com.google.android.gms.internal.zzafg$zza.onTransact(Unknown Source)
at android.os.Binder.execTransact(Binder.java:367)
at dalvik.system.NativeStart.run(Native Method)
这就是它的解码方式 -
请帮助,在此先感谢。