From a30854cccc4233162ca7b308db6f41a7dbfc2429 Mon Sep 17 00:00:00 2001 From: Charlie Cheever Date: Fri, 7 Feb 2020 18:57:07 -0800 Subject: [PATCH] [docs] Improve AppAuth docs (#6876) * [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 * Update docs/pages/versions/unversioned/sdk/app-auth.md lg Co-Authored-By: Evan Bacon * Update docs/pages/versions/unversioned/sdk/app-auth.md lg Co-Authored-By: Evan Bacon * Apply suggestions from code review Co-Authored-By: Evan Bacon * Apply suggestions from code review Co-Authored-By: Evan Bacon Co-authored-by: Evan Bacon --- .../versions/unversioned/sdk/app-auth.md | 134 ++++++++++-------- 1 file changed, 73 insertions(+), 61 deletions(-) diff --git a/docs/pages/versions/unversioned/sdk/app-auth.md b/docs/pages/versions/unversioned/sdk/app-auth.md index e94525db6785f..2e56b567bed94 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). + +Currently, this module only supports on Android, and iOS. Web support is planned to be added. Track it here: [Web support in expo-app-auth](https://github.com/expo/expo/issues/6883). + #### Platform Compatibility | Android Device | Android Emulator | iOS Device | iOS Simulator | Web | @@ -19,59 +26,84 @@ For [managed](../../introduction/managed-vs-bare/#managed-workflow) apps, you'll ## Usage -Below is a set of example functions that demonstrate how to use `expo-app-auth` with the Google OAuth Sign-In provider. + 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'; + + +```tsx +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 +