question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FR: relax JSON parsing of TokenResponse (and JsonWebToken)

See original GitHub issue

From michel.j…@e-office.com on November 28, 2012 00:30:25

Version of google-oauth-java-client (e.g. 1.5.0-beta)? 1.12.0

Java environment (e.g. Java 6, Android 2.3, App Engine)? AppEngine 1.7.3

Describe the problem. When consuming Microsoft Office365 OAuth services, the accessToken that is retrieved through:

AuthorizationCodeTokenRequest . execute() as per the sample, I get the error: number field formatted as a JSON string must use the @JsonString annotation How would you expect it to be fixed? In the JSONParser.java (from com.google.api.client.json) I commented out the Preconditions check, and now I have an accesstoken. And also the expires in has a value…

--------- start here -------

  case VALUE_STRING:

//        Preconditions.checkArgument(valueClass == null || !Number.class.isAssignableFrom(valueClass)
//            || fieldContext != null && fieldContext.getAnnotation(JsonString.class) != null,
//            "number field formatted as a JSON string must use the @JsonString annotation%s",
//            contextString);
        // TODO(yanivi): "special" values like Double.POSITIVE_INFINITY?
        try {
          return Data.parsePrimitiveValue(valueType, getText());
        } catch (IllegalArgumentException e) {
          throw new IllegalArgumentException(contextString, e);
        }

_Original issue: http://code.google.com/p/google-oauth-java-client/issues/detail?id=62_

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
dherbencommented, Sep 11, 2015

I’m having the same problem (with the expires_in formatted as a string) when authorizing against the ExactOnline accounting API.

I had managed to work around the problem for the initial token request by creating my own ExactOnlineResponseToken class (which maps the expires_in to a String) and executing the tokenRequest as such:

flow().newTokenRequest(authCode)
    .setRedirectUri(uri)
    .executeUnparsed()
    .parseAs(ExactOnlineTokenResponse.class)
    .toTokenResponse()

I feel this is better than having to tinker with the libraries themselves. Unfortunately, I still get the error when the Credential automatically tries to refresh the token, because that code is hardcoded in the Credential and I can’t access it.

Any plans on making the library more permissive in the near future? I guess I could perform my own checks before each request, proactively refreshing the token when necessary, although that feels hackish.

0reactions
Rinitha1commented, Jun 26, 2019

Hi would like to know how do we modify the JSONParser claas or the TokenResponse class as they are in the jar file. Would be very helpful if anyone can share the steps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

using restsharp for JWT for JSON parsing to object doesn't work
I'm using Restsharp to do RestApi and using JWT auth. The code is simple like this. I think it the response content will...
Read more >
draft-ietf-oauth-access-token-jwt-13
JSON Web Token (JWT) Profile for OAuth 2.0 Access Tokens (Internet-Draft, 2021) ... a format that can be parsed and validated by resource...
Read more >
Using JWT RBAC - Quarkus
Parse and Verify JsonWebToken with JWTParser. If the JWT token can not be injected, for example, if it is embedded in the service...
Read more >
Configuration :: SmallRye documentation
Configuration. Table of contents. MicroProfile JWT properties; Supported Public Key Formats; SmallRye JWT properties; Create JsonWebToken with JWTParser; Token ...
Read more >
Decode JWTs in C# for Authorization | Okta Developer
Many modern web apps use JSON Web Tokens (JWTs) during the ... If you already have a JWT and you just want to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found