FormidableLabs/react-native-app-auth

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:

  1. GitHub have implemented the OAuth spec incorrectly in that they default to returning responses in XML unless an Accept header requesting JSON is set
  2. AppAuth-Android have implemented the workaround
  3. 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.

I've emailed GitHub support although it is unlikely anything will come of it...

screen shot 2018-10-10 at 21 33 25

@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:

  1. fork AppAuth-ios
  2. make a commit with the header change to master
  3. in your Podfile, install AppAuth from your fork
  4. ...
  5. 🎉

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