From 761754ab8d92cc16b37bafd5f69804fc187b4619 Mon Sep 17 00:00:00 2001 From: Charlie Cheever Date: Tue, 28 Jan 2020 02:25:45 -0800 Subject: [PATCH 1/5] [docs] Improve AppAuth docs - Explain OAuth a little bit more - Mention that there are specialized modules for Google and Facebook - Give a complete example as an inline Snack rather than just as sourc code --- .../versions/unversioned/sdk/app-auth.md | 131 ++++++++++-------- 1 file changed, 72 insertions(+), 59 deletions(-) diff --git a/docs/pages/versions/unversioned/sdk/app-auth.md b/docs/pages/versions/unversioned/sdk/app-auth.md index e94525db6785f..ae27473ccf630 100644 --- a/docs/pages/versions/unversioned/sdk/app-auth.md +++ b/docs/pages/versions/unversioned/sdk/app-auth.md @@ -3,10 +3,17 @@ title: AppAuth sourceCodeUrl: 'https://github.com/expo/expo/tree/sdk-36/packages/expo-app-auth' --- +import SnackInline from '~/components/plugins/SnackInline'; import TableOfContentSection from '~/components/plugins/TableOfContentSection'; **`expo-app-auth`** allows you to authenticate and authorize your users through the native OAuth library AppAuth by [OpenID](https://github.com/openid). +Many services that let you authenticate with them or login with them, like GitHub, Google, GitLab, etc., use the OAuth 2.0 protocol. It's the industry standard. + +If you are trying to implement sign in with [Google](../google-sign-in) or [Facebook](../facebook), there are special modules in the Expo SDK for those (though this module will work). + +For now, this module only works on Anroid and iOS, but web support is possible is planned to be added. + #### Platform Compatibility | Android Device | Android Emulator | iOS Device | iOS Simulator | Web | @@ -21,57 +28,83 @@ For [managed](../../introduction/managed-vs-bare/#managed-workflow) apps, you'll Below is a set of example functions that demonstrate how to use `expo-app-auth` with the Google OAuth Sign-In provider. + + ```js -import { AsyncStorage } from 'react-native'; +import React, { useEffect, useState } from 'react'; +import { AsyncStorage, Button, StyleSheet, Text, View } from 'react-native'; import * as AppAuth from 'expo-app-auth'; -const config = { +export default function App() { + let [authState, setAuthState] = useState(null); + + useEffect(() => { + (async () => { + let cachedAuth = await getCachedAuthAsync(); + if (cachedAuth && !authState) { + setAuthState(cachedAuth); + } + })(); + }, []); + + return ( + + Expo AppAuth Example + +