-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
67 lines (59 loc) · 1.69 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import React, { Component } from 'react'
import { ScrollView, Text, TouchableOpacity, StyleSheet } from 'react-native'
import { ISSUER, CLIENT_ID, REDIRECT_URL } from 'react-native-dotenv'
import { authorize, refresh, revoke } from 'react-native-app-auth'
const config = {
issuer: ISSUER,
clientId: CLIENT_ID,
redirectUrl: REDIRECT_URL,
scopes: ['openid', 'profile', 'offline_access']
}
class App extends Component {
state = { auth: null }
_authorize = async () => {
try {
const authState = await authorize(config)
this.setState({ auth: authState })
} catch (error) {
console.log(error)
}
}
_refreshToken = async () => {
try {
const refreshState = await refresh(config, { refreshToken: this.state.auth.refreshToken })
this.setState({ auth: refreshState })
} catch (error) {
console.log(error)
}
}
_revokeToken = async () => {
try {
await revoke(config, { tokenToRevoke: this.state.auth.accessToken, sendClientId: true })
this.setState({ auth: null })
} catch (error) {
console.log(error)
}
}
render() {
return (
<ScrollView style={styles.container}>
<Text>{JSON.stringify(this.state.auth)}</Text>
<TouchableOpacity onPress={this._authorize}>
<Text>Authorize</Text>
</TouchableOpacity>
<TouchableOpacity onPress={this._refreshToken}>
<Text>Refresh Token</Text>
</TouchableOpacity>
<TouchableOpacity onPress={this._revokeToken}>
<Text>Revoke Token</Text>
</TouchableOpacity>
</ScrollView>
)
}
}
const styles = StyleSheet.create({
container: {
marginTop: 20,
},
})
export default App