Skip to content

Commit cc3009e

Browse files
authored
Merge pull request #37 from FormidableLabs/feature/new-api
Feature/new api
2 parents 389d574 + 54831c1 commit cc3009e

File tree

7 files changed

+359
-287
lines changed

7 files changed

+359
-287
lines changed

Example/App.js

Lines changed: 19 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+
4645
this.animateState(
4746
{
4847
hasLoggedInOnce: true,
@@ -59,7 +58,10 @@ 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(config, {
62+
refreshToken: this.state.refreshToken
63+
});
64+
6365
this.animateState({
6466
accessToken: authState.accessToken || this.state.accessToken,
6567
accessTokenExpirationDate:
@@ -73,7 +75,10 @@ export default class App extends Component<{}, State> {
7375

7476
revoke = async () => {
7577
try {
76-
await this.auth.revokeToken(this.state.accessToken, true);
78+
await revoke(config, {
79+
tokenToRevoke: this.state.accessToken,
80+
sendClientId: true
81+
});
7782
this.animateState({
7883
accessToken: '',
7984
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#b4a33ba178bddf1528066d1b5198d7d01d8693ad",
1313
"styled-components": "^2.2.3"
1414
},
1515
"devDependencies": {

0 commit comments

Comments
 (0)