Skip to content

Commit d16e9d3

Browse files
committed
Updated README
1 parent 809bf3d commit d16e9d3

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

README.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,48 @@ We can use an external authentication provider, such as twitter/facebook for aut
172172

173173
> By using a separate library, we can keep our dependencies a little lower and the size of the application down.
174174
175+
### OAuth setup with library
176+
175177
We'll use the [react-native-oauth](https://github.com/fullstackreact/react-native-oauth) library, which was built along-side [Firestack](https://github.com/fullstackreact/react-native-firestack) specifically to handle authentication through third-party providers.
176178

177179
> If you prefer to use another library, make sure you pass through the `oauthToken` and `oauthTokenSecret` provided by your other library to call the `signInWithProvider()` method.
178180
179-
Following the instructions at
181+
Following the instructions on the [react-native-oauth README](https://github.com/fullstackreact/react-native-oauth), we'll need to install it using `npm`:
182+
183+
```javascript
184+
npm install --save react-native-oauth
185+
```
186+
187+
It's important to set up the authentication library fully with our app configuration. Make sure to configure your app [along with this step](https://github.com/fullstackreact/react-native-oauth#handle-deep-linking-loading) otherwise authentication _cannot_ work.
188+
189+
Once the app is configured with the instructions, we can call the `oauthManager`'s (or other library's) login method. We'll need to hold on to the `oauthToken` and an `oauthTokenSecret` provided by the provider. Using these values, we can call the `signInWithProvider()` method. The `signInWithProvider()` method accepts three parameters:
190+
191+
1. The provider (such as `twitter`, `facebook`, etc) name
192+
2. The `authToken` value granted by the provider
193+
3. The `authTokenSecret` value granted by the provider
194+
195+
```javascript
196+
// For instance, using the react-native-oauth library, this process
197+
// looks like:
198+
199+
const appUrl = 'app-uri://oauth-callback/twitter'
200+
authManager.authorizeWithCallbackURL('twitter', appUrl)
201+
.then(creds => {
202+
return server.signInWithProvider('twitter', creds.oauth_token creds.oauth_token_secret)
203+
.then(() => {
204+
// We're now signed in through Firebase
205+
})
206+
.catch(err => {
207+
// There was an error
208+
})
209+
})
210+
```
180211

181-
...
212+
If the `signInWithProvider()` method resolves correct and we have already set up our `listenForAuth()` method properly, it will fire and we'll have a logged in user through Firebase.
182213

183214
### reauthenticateWithCredentialForProvider()
184215

185-
...
216+
When the auth token has expired, we can ask firebase to reauthenticate with the provider. This method accepts the _same_ arguments as `signInWithProvider()` accepts.
186217

187218
#### updateUserEmail()
188219

firestack.ios.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,24 @@ export default class Firestack {
6969
return promisify('signInWithEmail')(email, password);
7070
}
7171

72+
/**
73+
* Sign the user in with a third-party authentication provider
74+
* @param {string} provider The name of the provider to use for login
75+
* @param {string} authToken The authToken granted by the provider
76+
* @param {string} authSecret The authToken secret granted by the provider
77+
* @return {Promise} A promise resolved upon completion
78+
*/
7279
signInWithProvider(provider, authToken, authSecret) {
7380
return promisify('signInWithProvider')(provider, authToken, authSecret);
7481
}
7582

83+
/**
84+
* Reauthenticate a user with a third-party authentication provider
85+
* @param {string} provider The provider name
86+
* @param {string} token The authToken granted by the provider
87+
* @param {string} secret The authTokenSecret granted by the provider
88+
* @return {Promise} A promise resolved upon completion
89+
*/
7690
reauthenticateWithCredentialForProvider(provider, token, secret) {
7791
return promisify('reauthenticateWithCredentialForProvider')(provider, token, secret);
7892
}

0 commit comments

Comments
 (0)