1
- // @flow
2
-
3
1
import React , { Component } from 'react' ;
4
2
import { UIManager , LayoutAnimation } from 'react-native' ;
5
- import AppAuth from 'react-native-app-auth' ;
3
+ import { authorize , refresh , revoke } from 'react-native-app-auth' ;
6
4
import { Page , Button , ButtonContainer , Form , Heading } from './components' ;
7
5
8
6
UIManager . setLayoutAnimationEnabledExperimental &&
9
7
UIManager . setLayoutAnimationEnabledExperimental ( true ) ;
10
8
11
- const scopes = [ 'openid' , 'profile' , 'email' , 'offline_access' ] ;
12
-
13
9
type State = {
14
10
hasLoggedInOnce : boolean ,
15
11
accessToken : ?string ,
16
12
accessTokenExpirationDate : ?string ,
17
13
refreshToken : ?string
18
14
} ;
19
15
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
+ } ;
26
23
24
+ export default class App extends Component < { } , State > {
27
25
state = {
28
26
hasLoggedInOnce : false ,
29
27
accessToken : '' ,
@@ -42,7 +40,8 @@ export default class App extends Component<{}, State> {
42
40
43
41
authorize = async ( ) => {
44
42
try {
45
- const authState = await this . auth . authorize ( scopes ) ;
43
+ const authState = await authorize ( config ) ;
44
+
46
45
this . animateState (
47
46
{
48
47
hasLoggedInOnce : true ,
@@ -59,7 +58,10 @@ export default class App extends Component<{}, State> {
59
58
60
59
refresh = async ( ) = > {
61
60
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
+
63
65
this . animateState ( {
64
66
accessToken : authState . accessToken || this . state . accessToken ,
65
67
accessTokenExpirationDate :
@@ -73,7 +75,10 @@ export default class App extends Component<{}, State> {
73
75
74
76
revoke = async ( ) = > {
75
77
try {
76
- await this . auth . revokeToken ( this . state . accessToken , true ) ;
78
+ await revoke ( config , {
79
+ tokenToRevoke : this . state . accessToken ,
80
+ sendClientId : true
81
+ } ) ;
77
82
this . animateState ( {
78
83
accessToken : '' ,
79
84
accessTokenExpirationDate : '' ,
0 commit comments