Skip to content

Commit 3063886

Browse files
committed
Fixed scopes on Android (#29) and added Slack insructions to README (ios only)
1 parent 17b47ac commit 3063886

File tree

7 files changed

+51
-7
lines changed

7 files changed

+51
-7
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The `react-native-oauth` library provides an interface to OAuth 1.0 and OAuth 2.
66
* Facebook
77
* Google
88
* Github
9+
* Slack (iOS)
910

1011
## TL;DR;
1112

@@ -328,6 +329,35 @@ const config = {
328329
}
329330
```
330331

332+
## Slack (iOS)
333+
334+
Currently implemented only for iOS, Slack support is ready to go. We'll need to create an app first. Head to the slack developer docs at [https://slack.com/developers](https://slack.com/developers).
335+
336+
![](./resources/slack/dev.png)
337+
338+
Click on the Getting Started button:
339+
340+
![](./resources/slack/getting_started.png)
341+
342+
From here, find the `create an app` link:
343+
344+
![](./resources/slack/create.png)
345+
346+
Take note of the `client_id` and the `client_secret`. We'll place these in our configuration object just like so:
347+
348+
```javascript
349+
const config = {
350+
slack: {
351+
client_id: 'YOUR_CLIENT_ID',
352+
client_secret: 'YOUR_CLIENT_SECRET'
353+
}
354+
}
355+
```
356+
357+
Lastly, Slack requires us to add a redirect_url. By default, the callback_url pattern is `${app_name}://oauth`, so make sure to add your redirect_url where it asks for them before starting to work with the API.
358+
359+
![](./resources/slack/redirect.png)
360+
331361
## Authenticating against our providers
332362

333363
We can use the manager in our app using the `authorize()` method on the manager.
@@ -364,6 +394,16 @@ The `resp` object is set as follows:
364394
}
365395
```
366396

397+
The second argument accepts an object where we can ask for additional scopes, override default values, etc.
398+
399+
```javascript
400+
manager.authorize('google', {scopes: 'email,profile'})
401+
.then(resp => console.log(resp))
402+
.catch(err => console.log(err));
403+
```
404+
405+
* Scopes are a list of scopes _comma separated_ as a string.
406+
367407
## Calling a provider's API
368408

369409
We can use OAuthManager to make requests to endpoints from our providers as well. For instance, let's say we want to get a user's time line from twitter. We would make the request to the url [https://api.twitter.com/1.1/statuses/user_timeline.json](https://api.twitter.com/1.1/statuses/user_timeline.json)

android/src/main/java/io/fullstack/oauth/OAuthManagerProviders.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private static OAuth10aService twitterService(final HashMap cfg, final String ca
6262

6363
String scopes = (String) cfg.get("scopes");
6464
if (scopes != null) {
65-
builder.scopes(scopes);
65+
builder.scope(scopes);
6666
}
6767

6868
if (callbackUrl != null) {
@@ -87,6 +87,11 @@ private static OAuth20Service facebookService(final HashMap cfg, final String ca
8787
.apiSecret(clientSecret)
8888
.state(state)
8989
.debug();
90+
91+
String scopes = (String) cfg.get("scopes");
92+
if (scopes != null) {
93+
builder.scope(scopes);
94+
}
9095

9196
if (callbackUrl != null) {
9297
builder.callback(callbackUrl);
@@ -104,9 +109,10 @@ private static OAuth20Service googleService(final HashMap cfg, final String call
104109
} else {
105110
state = TAG + new Random().nextInt(999_999);
106111
}
112+
107113
String scope = "profile";
108-
if (cfg.containsKey("scope")) {
109-
scope = (String) cfg.get("scope");
114+
if (cfg.containsKey("scopes")) {
115+
scope = (String) cfg.get("scopes");
110116
}
111117

112118
ServiceBuilder builder = new ServiceBuilder()
@@ -133,8 +139,8 @@ private static OAuth20Service githubService(final HashMap cfg, final String call
133139
state = TAG + new Random().nextInt(999_999);
134140
}
135141
String scope = "profile";
136-
if (cfg.containsKey("scope")) {
137-
scope = (String) cfg.get("scope");
142+
if (cfg.containsKey("scopes")) {
143+
scope = (String) cfg.get("scopes");
138144
}
139145

140146
ServiceBuilder builder = new ServiceBuilder()
@@ -148,8 +154,6 @@ private static OAuth20Service githubService(final HashMap cfg, final String call
148154
builder.callback(callbackUrl);
149155
}
150156

151-
Log.d(TAG, "builder ---> " + callbackUrl);
152-
153157
return builder.build(GitHubApi.instance());
154158
}
155159
}

resources/slack/create.png

2.36 MB
Loading

resources/slack/creds.png

1.31 MB
Loading

resources/slack/dev.png

1.02 MB
Loading

resources/slack/getting_started.png

1.37 MB
Loading

resources/slack/redirect.png

1.35 MB
Loading

0 commit comments

Comments
 (0)