Skip to content

Commit 29de148

Browse files
author
Kadi Kraman
authored
Merge pull request #449 from FormidableLabs/chore/spotify-example
Chore/spotify example
2 parents 0db2d0a + ff7ebcd commit 29de148

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

Example/App.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useCallback } from 'react';
1+
import React, { useState, useCallback, useMemo } from 'react';
22
import { UIManager, LayoutAnimation, Alert } from 'react-native';
33
import { authorize, refresh, revoke } from 'react-native-app-auth';
44
import { Page, Button, ButtonContainer, Form, FormLabel, FormValue, Heading } from './components';
@@ -59,7 +59,8 @@ export default () => {
5959

6060
setAuthState(current => ({
6161
...current,
62-
...newAuthState
62+
...newAuthState,
63+
refreshToken: newAuthState.refreshToken || current.refreshToken
6364
}))
6465

6566
} catch (error) {
@@ -84,6 +85,15 @@ export default () => {
8485
}
8586
}, [authState]);
8687

88+
const showRevoke = useMemo(() => {
89+
if (authState.accessToken) {
90+
if (config.issuer || config.serviceConfiguration.revocationEndpoint) {
91+
return true;
92+
}
93+
}
94+
return false;
95+
}, [authState]);
96+
8797
return (
8898
<Page>
8999
{!!authState.accessToken ? (
@@ -108,7 +118,7 @@ export default () => {
108118
{!!authState.refreshToken ? (
109119
<Button onPress={handleRefresh} text="Refresh" color="#24C2CB" />
110120
) : null}
111-
{!!authState.accessToken ? (
121+
{showRevoke ? (
112122
<Button onPress={handleRevoke} text="Revoke" color="#EF525B" />
113123
) : null}
114124
</ButtonContainer>

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ These providers implement the OAuth2 spec, but are not OpenID providers, which m
4242
- [GitHub](https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps/) ([Example configuration](./docs/config-examples/github.md))
4343
- [Slack](https://api.slack.com/authentication/oauth-v2) ([Example configuration](./docs/config-examples/slack.md))
4444
- [Strava](https://developers.strava.com/docs/authentication) ([Example configuration](./docs/config-examples/strava.md))
45+
- [Spotify](https://developer.spotify.com/documentation/general/guides/authorization-guide/) ([Example configuration](./docs/config-examples/spotify.md))
4546

4647
## Why you may want to use this library
4748

docs/config-examples/spotify.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Spotify
2+
3+
If you don't already have a spotify app, create it [here](https://developer.spotify.com/dashboard/applications).
4+
5+
Open your app, go to settings and add a redirect uri, e.g. `com.myapp:/oauth`.
6+
7+
Note: iOS redirect on Spotify only works with one `/`.s
8+
9+
```js
10+
const config = {
11+
clientId: '<client_id>', // available on the app page
12+
clientSecret: '<client_secret>', // click "show client secret" to see this
13+
redirectUrl: 'com.myapp:/oauth', // the redirect you defined after creating the app
14+
scopes: ['user-read-email', 'playlist-modify-public', 'user-read-private'], // the scopes you need to access
15+
serviceConfiguration: {
16+
authorizationEndpoint: 'https://accounts.spotify.com/authorize',
17+
tokenEndpoint: 'https://accounts.spotify.com/api/token',
18+
},
19+
};
20+
21+
const authState = await authorize(config);
22+
```

0 commit comments

Comments
 (0)