Skip to content

Commit 06f9f98

Browse files
author
Kadi Kraman
committed
Update the example app to use new API
1 parent 897b3eb commit 06f9f98

File tree

4 files changed

+176
-141
lines changed

4 files changed

+176
-141
lines changed

Example/App.js

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
1-
// @flow
2-
31
import React, { Component } from 'react';
42
import { UIManager, LayoutAnimation } from 'react-native';
5-
import AppAuth from 'react-native-app-auth';
3+
import { authorize, refresh, revoke } from 'react-native-app-auth';
64
import { Page, Button, ButtonContainer, Form, Heading } from './components';
75

86
UIManager.setLayoutAnimationEnabledExperimental &&
97
UIManager.setLayoutAnimationEnabledExperimental(true);
108

11-
const scopes = ['openid', 'profile', 'email', 'offline_access'];
12-
139
type State = {
1410
hasLoggedInOnce: boolean,
1511
accessToken: ?string,
1612
accessTokenExpirationDate: ?string,
1713
refreshToken: ?string
1814
};
1915

20-
export default class App extends Component<{}, State> {
21-
auth = new AppAuth({
22-
issuer: 'https://demo.identityserver.io',
23-
clientId: 'native.code',
24-
redirectUrl: 'io.identityserver.demo:/oauthredirect'
25-
});
16+
const config = {
17+
issuer: 'https://demo.identityserver.io',
18+
clientId: 'native.code',
19+
redirectUrl: 'io.identityserver.demo:/oauthredirect',
20+
additionalParameters: {},
21+
scopes: ['openid', 'profile', 'email', 'offline_access']
22+
};
2623

24+
export default class App extends Component<{}, State> {
2725
state = {
2826
hasLoggedInOnce: false,
2927
accessToken: '',
@@ -42,7 +40,8 @@ export default class App extends Component<{}, State> {
4240

4341
authorize = async () => {
4442
try {
45-
const authState = await this.auth.authorize(scopes);
43+
const authState = await authorize(config);
44+
console.log('auth result ', authState);
4645
this.animateState(
4746
{
4847
hasLoggedInOnce: true,
@@ -59,7 +58,12 @@ export default class App extends Component<{}, State> {
5958

6059
refresh = async () => {
6160
try {
62-
const authState = await this.auth.refresh(this.state.refreshToken, scopes);
61+
const authState = await refresh({
62+
...config,
63+
refreshToken: this.state.refreshToken
64+
});
65+
console.log('refresh result ', authState);
66+
6367
this.animateState({
6468
accessToken: authState.accessToken || this.state.accessToken,
6569
accessTokenExpirationDate:
@@ -73,7 +77,11 @@ export default class App extends Component<{}, State> {
7377

7478
revoke = async () => {
7579
try {
76-
await this.auth.revokeToken(this.state.accessToken, true);
80+
await revoke({
81+
...config,
82+
tokenToRevoke: this.state.accessToken,
83+
sendClientId: true
84+
});
7785
this.animateState({
7886
accessToken: '',
7987
accessTokenExpirationDate: '',

Example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"dependencies": {
1010
"react": "16.0.0",
1111
"react-native": "0.50.3",
12-
"react-native-app-auth": "^1.0.1",
12+
"react-native-app-auth": "git+https://git@github.com/FormidableLabs/react-native-app-auth.git#96f57eab7f0b2388bb2f3c87897ff3decaeebef6",
1313
"styled-components": "^2.2.3"
1414
},
1515
"devDependencies": {

0 commit comments

Comments
 (0)