Skip to content

Added method for adding own providers via OAuthManager #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,21 @@ We can `deauthorize()` our user's from using the provider by calling the `deauth
manager.deauthorize('twitter');
```

## Adding your own providers

To add your own providers you can use the `addProvider()` method and fill in your provider details:

```javascript
manager.addProvider({
'name_of_provider': {
auth_version: '2.0',
authorize_url: 'https://provider.dev/oauth',
access_token_url: 'https://provider.dev/oauth/token',
callback_url: ({app_name}) => `${app_name}://oauth`,
}
});
```

## Contributing

This is _open-source_ software and we can make it rock for everyone through contributions.
Expand Down
14 changes: 10 additions & 4 deletions react-native-oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const OAuthManagerBridge = NativeModules.OAuthManager;
let configured = false;
const STORAGE_KEY = 'ReactNativeOAuth';
import promisify from './lib/promisify'
import authProviders from './lib/authProviders';
import defaultProviders from './lib/authProviders';

let authProviders = defaultProviders;

const identity = (props) => props;
/**
Expand All @@ -27,6 +29,10 @@ export default class OAuthManager {
this._options = opts;
}

addProvider(provider) {
Object.assign({}, authProviders, provider);
}

configure(providerConfigs) {
return this.configureProviders(providerConfigs)
}
Expand Down Expand Up @@ -99,11 +105,11 @@ export default class OAuthManager {
// Private
/**
* Configure a single provider
*
*
*
*
* @param {string} name of the provider
* @param {object} additional configuration
*
*
**/
configureProvider(name, props) {
invariant(OAuthManager.isSupported(name), `The provider ${name} is not supported yet`);
Expand Down