## OAuth and Federation Overview [OAuth 2.0](https://en.wikipedia.org/wiki/OAuth) is the common Authorization framework used by web and mobile applications for getting access to user information ("scopes") in a limited manner. Common analogies you will hear in OAuth is that of boarding a plane or staying in a hotel - showing your identification is the Authentication piece (signing into an app) and using the boarding pass/hotel key is what you are Authorized to access. OAuth support in Amplify uses Cognito User Pools and supports federation with social providers, which will automatically create a corresponding user in the User Pool after a login. [OIDC](https://en.wikipedia.org/wiki/OpenID_Connect) tokens are available in the app after the application has completed this process. import all0 from "/src/fragments/lib/auth/common/social_signin_web_ui/setup_auth_provider.mdx"; ## Configure Auth Category Once you have the social provider configured, run the following in your project’s root folder: ```bash amplify add auth ## "amplify update auth" if already configured ``` Choose the following options: ```console ? Do you want to use the default authentication and security configuration? `Default configuration with Social Provider (Federation)` ? How do you want users to be able to sign in? `Username` ? Do you want to configure advanced settings? `No, I am done.` ? What domain name prefix you want us to create for you? `(default)` ? Enter your redirect signin URI: `myapp://` ? Do you want to add another redirect signin URI `No` ? Enter your redirect signout URI: `myapp://` ? Do you want to add another redirect signout URI `No` ? Select the social providers you want to configure for your user pool: `` ``` You can configure you application to use more than one redirect URL. For more information, refer to the [Redirect URLs](#redirect-urls) section. import all1 from "/src/fragments/lib/auth/common/social_signin_web_ui/configure_auth_category.mdx"; ## Setup frontend After configuring the OAuth endpoints (Cognito Hosted UI), you can integrate your App by invoking `Auth.federatedSignIn()` function. Passing `LoginWithAmazon`, `Facebook`, `Google`, or `SignInWithApple` on the `provider` argument (e.g `Auth.federatedSignIn({ provider: 'LoginWithAmazon' })`) will bypass the Hosted UI and federate immediately with the social provider as shown in the below React Native example. If you are looking to add a custom state, you are able to do so by passing a string (e.g. `Auth.federatedSignIn({ customState: 'xyz' })`) value and listening for the custom state via Hub. ```ts import { useEffect, useState } from "react"; import { Text, View, Linking, Button } from "react-native"; import { CognitoHostedUIIdentityProvider } from "@aws-amplify/auth"; import { Amplify, Auth, Hub } from "aws-amplify"; import awsconfig from "./aws-exports"; Amplify.configure(awsconfig); export default function App() { const [user, setUser] = useState(null); const [customState, setCustomState] = useState(null); useEffect(() => { const unsubscribe = Hub.listen("auth", ({ payload: { event, data }}) => { switch (event) { case "signIn": setUser(data); break; case "signOut": setUser(null); break; case "customOAuthState": setCustomState(data); } }); getUser(); return unsubscribe; }, []); const getUser = async (): Promise => { try { const currentUser = await Auth.currentAuthenticatedUser(); setUser(currentUser); } catch(error) { console.error(error); console.log("Not signed in"); } }; return (