Comments (6)
- 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.
@2piix
do you have any update?
from hoauth2.
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:
hoauth2/src/Network/OAuth/OAuth2/Internal.hs
Lines 53 to 59 in c289d68
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.
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.
1.8.1
was released and let me know if it solved your problem. thank you for reporting the problem.
from hoauth2.
Good to go, feel free to close this out!
from hoauth2.
Related Issues (20)
- Shall `mkAuthorizationRequest` return `URI` instead of `Text`
- Rename mkAuthorizeRequest HOT 1
- Rename Facebook to Meta HOT 1
- Move `defaultXXXApp` to hoauth2-demo and rename to `SampleXXXAuthCodeApp` HOT 1
- Unable to parse Client credential token response error (Okta)
- Try DataKind on IdpName that is Enum type HOT 1
- Fixes sample.env.json HOT 1
- Fixes the parameter order in the OAuth2 http client
- Use some approaches to create all possible `IdpName` for UI to render
- `data RefreshTokenRequest` looks unnecessary
- `Data.HashMap` v.s. `Data.Map`
- Add experiment module sample app into hoauth2-tutorial
- Rename OAuth2Token to TokenResponse
- Move `OAuth.OAuth2.hs` to `OAuth2.hs`
- Consider to remove those deprecated methods
- `Idp i` and type safety
- CHANGELOG missing HOT 2
- Candidate for 2.11.0 has outdated dependencies HOT 1
- Strengthen `base` lower bound to `>= 4.14`. HOT 1
- hoauth2-providers 0.7.1 build fail HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hoauth2.