1- // @flow
2-
31import React , { Component } from 'react' ;
42import { UIManager , LayoutAnimation } from 'react-native' ;
5- import AppAuth from 'react-native-app-auth' ;
3+ import { authorize , refresh , revoke } from 'react-native-app-auth' ;
64import { Page , Button , ButtonContainer , Form , Heading } from './components' ;
75
86UIManager . setLayoutAnimationEnabledExperimental &&
97 UIManager . setLayoutAnimationEnabledExperimental ( true ) ;
108
11- const scopes = [ 'openid' , 'profile' , 'email' , 'offline_access' ] ;
12-
139type 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 : '' ,
0 commit comments