Skip to content

cjcodes/react-native-simple-auth

 
 

Repository files navigation

react-native-simple-auth Build Status

SimpleAuth iOS wrapper for React Native

Screencast

Screencast

Install

  1. Install react native and make sure it works. There are currently two supported approaches for installing React-Native, npm or CocoaPods. Users have found the npm approach more stable for this library.
  2. npm install react-native-simple-auth
  3. In XCode, in the project navigator right click LibrariesAdd Files to [your project's name]
  4. Go to node_modulesreact-native-simple-auth➜ iOS and add SimpleAuthWrapper.h and SimpleAuthWrapper.m
  5. Go to your project's root directory and add a Podfile similar to this example.
  • You may need to tell the podfile where to find your xcode project by adding the following to the podfile: xcodeproj './path/to/your/.xcodeproj/project'
  1. Install CocoaPods https://guides.cocoapods.org/using/getting-started.html
  2. Run pod install

If you encounter problems building the project after this, the following install tips may be of help.

Usage

Create a configuration object for each of the providers you want to authorize with (required keys are in parenthesis):

  • google-web (client_id, client_secret)
  • facebook (app_id)
  • twitter (consumer_key, consumer_secret)
  • instagram (client_id, redirect_uri)
  • tumblr (consumer_key, consumer_secret)
  • linkedin-web (client_id, client_secret, redirect_uri)

See secrets.example.js.

Other providers supported by SimpleAuth may work, but haven't been tested.

Create an instance of the SimpleAuthWrapper library:

let simpleAuthClient = require('react-native-simple-auth');

Configure the library with a single provider:

simpleAuthClient.configure('twitter', {
  consumer_key: 'KEY',
  consumer_secret: 'SECRET'
}).then(() => {
  // Twitter is configured.
})

Or multiple providers:

simpleAuthClient.configure({
  twitter: {
    consumer_key: 'KEY',
    consumer_secret: 'SECRET'
  },
  facebook: {
    app_id: 'ID'
  }
}).then(() => {
  // Twitter & Facebook are configured.
});

Then authorize each provider:

simpleAuthClient.authorize('twitter').then((info) => {
  let token = info.token;
  let name = info.name;
}).catch((error) => {
  let errorCode = error.code;
  let errorDescription = error.description;
});

License

react-native-simple-auth is released under the MIT license.

Thanks

About

SimpleAuth iOS wrapper for React Native

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 58.8%
  • Objective-C 39.8%
  • Ruby 1.4%