Skip to content
This repository has been archived by the owner on Feb 21, 2020. It is now read-only.

Add nonce #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
StyleSheet,
Text,
View,
AsyncStorage,
} from 'react-native';
import jwtDecoder from 'jwt-decode';

Expand Down Expand Up @@ -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,
}),
});
Expand All @@ -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 (
<View style={styles.container}>
Expand Down