Usage with GitHub oauth
tobiastimm opened this issue · 7 comments
Request for information
I've tried to create a login via GitHub. I've successfully authorised via the app, but when AppAuth is trying to read the token response the console is saying
Error: JSON error parsing token response: The data couldn’t be read because it isn’t in the correct format.
at createErrorFromErrorData (NativeModules.js:146)
at NativeModules.js:95
at MessageQueue.__invokeCallback (MessageQueue.js:397)
at MessageQueue.js:127
at MessageQueue.__guard (MessageQueue.js:297)
at MessageQueue.invokeCallbackAndReturnFlushedQueue (MessageQueue.js:126)
at debuggerWorker.js:72
My config for GitHub is:
const config = {
clientId: 'MY_ID',
clientSecret: 'MY_SECRET,
redirectUrl: 'gaiden://oauth',
scopes: [
'repo',
'notifications',
'user',
],
serviceConfiguration: {
authorizationEndpoint: 'https://github.com/login/oauth/authorize',
tokenEndpoint: 'https://github.com/login/oauth/access_token',
revocationEndpoint:
'https://github.com/settings/connections/applications/MY_ID'
}
}
Would appreciate any help 😄
Hi @tobiastimm - as it is currently, this library can't be used to authenticate with GitHub. Or rather, Android will work, but iOS will not.
Long story short:
- GitHub have implemented the OAuth spec incorrectly in that they default to returning responses in XML unless an Accept header requesting JSON is set
- AppAuth-Android have implemented the workaround
- AppAuth-iOS have refused to so do. I made a PR for it, you can see the discussion here: openid/AppAuth-iOS#206
Now, if you really want to make this work, depending on how you installed the AppAuth-iOS dependency, you can either manually edit the native code in your project to add the accept header (as in my PR) or fork the library and add it.
@kadikraman thanks for your response 😄 that is unfortunately, but I will try to add your changes to a fork or the native code directly.
@kadikraman it works now. Thanks for your help! Really appreciate it
I want to do this for github, how can I edit the source file. I just see 'react-native-auth-app' in my node_modules, not the original library. I have no clue how to edit that.
If you're using Pods, there should be a OIDTokenRequest.m file somewhere in ios/Pods/AppAuth - that's what needs changing. However since that is installed via Pods dynamically, in order to use it on CI, you'd need to:
- fork AppAuth-ios
- make a commit with the header change to master
- in your Podfile, install AppAuth from your fork
- ...
- 🎉
alternative solution would be to maintain a 'pod_patches' directory with the patch and in postinstall in Podfile, apply the patch, similar to how patch_package works in the node/npm ecosystem
