Giter Site home page Giter Site logo

Comments (6)

freizl avatar freizl commented on August 25, 2024
  • The parsing error due to the problem found at #65
  • dig more I think the problem is that handleResponse (definition below) expects successful response but error.
  • rather invoke parseResponseJSON . handleResponse, you might want to write your own handle response function to log out the response in string and response code to see what's going on
handleResponse :: FromJSON err => Response BSL.ByteString -> OAuth2Result err BSL.ByteString
handleResponse rsp =
    if HT.statusIsSuccessful (responseStatus rsp)
        then Right $ responseBody rsp
        else Left $ parseOAuth2Error (responseBody rsp)

from hoauth2.

freizl avatar freizl commented on August 25, 2024

@2piix
do you have any update?

from hoauth2.

cbeav avatar cbeav commented on August 25, 2024

Yo! Hoping to revive this, came across the same issue this week, buried in the same misleading error. Took me a second to diagnose it here.

The problem in parsing the JSON above is this line:

"expires_in": "3599"

You'll note this doesn't play well with the default Aeson parsing definition of Maybe Int present in the OAuth2Token data definition:

data OAuth2Token = OAuth2Token {
accessToken :: AccessToken
, refreshToken :: Maybe RefreshToken
, expiresIn :: Maybe Int
, tokenType :: Maybe Text
, idToken :: Maybe IdToken
} deriving (Show, Generic)

I think it would be cool to try to parse Int using withText upstream, but maybe not worth fighting that battle for this one fix.

How would we feel about me writing a custom fromJSON for OAuth2Token here with the flexibility of parsing from a string in addition to the default Int parser?

from hoauth2.

cbeav avatar cbeav commented on August 25, 2024

Suggestions for how to do this more cleanly welcome:

data OAuth2Token = OAuth2Token {
      accessToken  :: AccessToken
    , refreshToken :: Maybe RefreshToken
    , expiresIn    :: Maybe Int
    , tokenType    :: Maybe Text
    , idToken      :: Maybe IdToken
    } deriving (Show, Generic)

parseIntFlexible :: Value -> Parser Int
parseIntFlexible (String s) = pure . read $ unpack s
parseIntFlexible v = parseJSON v

-- | Parse JSON data into 'OAuth2Token'
instance FromJSON OAuth2Token where
    parseJSON = withObject "OAuth2Token" $ \v -> OAuth2Token
        <$> v .: "access_token"
        <*> v .:? "refresh_token"
        <*> explicitParseFieldMaybe parseIntFlexible v "expires_in"
        <*> v .:? "token_type"
        <*> v .:? "id_token"
instance ToJSON OAuth2Token where
    toJSON = genericToJSON defaultOptions { fieldLabelModifier = camelTo2 '_' }
    toEncoding = genericToEncoding defaultOptions { fieldLabelModifier = camelTo2 '_' }

from hoauth2.

freizl avatar freizl commented on August 25, 2024

1.8.1 was released and let me know if it solved your problem. thank you for reporting the problem.

from hoauth2.

cbeav avatar cbeav commented on August 25, 2024

Good to go, feel free to close this out!

from hoauth2.

Related Issues (20)

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.