diff --git a/main.js b/main.js index a8cda07..2fe47a8 100644 --- a/main.js +++ b/main.js @@ -6,6 +6,7 @@ import { StyleSheet, Text, View, + AsyncStorage, } from 'react-native'; import jwtDecoder from 'jwt-decode'; @@ -51,6 +52,7 @@ class App extends React.Component { client_id: auth0ClientId, response_type: 'token', scope: 'openid name', + nonce: await this.getNonce(), redirect_uri: redirectUrl, }), }); @@ -73,6 +75,23 @@ class App extends React.Component { this.setState({ username }); } + generateRandomString = length => { + const charset = + '0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._~'; + return [...Array(length)] + .map(() => charset.charAt(Math.floor(Math.random() * charset.length))) + .join(''); + }; + + getNonce = async () => { + let nonce = await AsyncStorage.getItem('nonce'); + if (!nonce) { + nonce = this.generateRandomString(16); + await AsyncStorage.setItem('nonce', nonce); + } + return nonce; + }; + render() { return (