<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Benny Carlsson on Medium]]></title>
        <description><![CDATA[Stories by Benny Carlsson on Medium]]></description>
        <link>https://medium.com/@carlsson.benny?source=rss-dc3d034c18a2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*e98v1PR5Z0z3VW65I5Hlsw.jpeg</url>
            <title>Stories by Benny Carlsson on Medium</title>
            <link>https://medium.com/@carlsson.benny?source=rss-dc3d034c18a2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 21:31:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@carlsson.benny/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Google Sign-in with React Native and Expo]]></title>
            <link>https://blog.expo.dev/google-sign-in-with-react-native-and-expo-9cac6c392f0e?source=rss-dc3d034c18a2------2</link>
            <guid isPermaLink="false">https://medium.com/p/9cac6c392f0e</guid>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Benny Carlsson]]></dc:creator>
            <pubDate>Thu, 28 Jun 2018 17:18:53 GMT</pubDate>
            <atom:updated>2018-06-28T17:18:53.196Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to add Google Sign-in to your Expo/ React-Native app without ejecting.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kov94YweGKGzQFwn" /><figcaption>Photo by <a href="https://unsplash.com/@michaelmroczek?utm_source=medium&amp;utm_medium=referral">Michael Mroczek</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FELXvcyiTTHM%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DELXvcyiTTHM&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FELXvcyiTTHM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f4f20c7feb8220a4321bf0e0b54cde2/href">https://medium.com/media/8f4f20c7feb8220a4321bf0e0b54cde2/href</a></iframe><h4>YouTube Video</h4><p>If you prefer a video format, this guide also exists as a YouTube video. Otherwise, keep reading!</p><h3>Expectations</h3><ul><li>We’ll make our targeting device an Android, but this guide should work for iPhone as well. A few steps are different for iOS, and those are noted in the guide.</li><li>We’ll use the web browser to sign in with google. (If you want to use the native Google Sign In SDK, this is not the guide for you, and you’ll need a standalone app or to <a href="https://github.com/react-community/create-react-native-app/blob/master/EJECTING.md">eject</a> your current Expo app.) But don’t worry, signing in with the browser still gives you an easy, smooth transition while remembering your credentials.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*P7RrPPwaqvVAIIBT0G6V1g.gif" /><figcaption>The end result</figcaption></figure><h3>Getting Started</h3><p>Start by creating an Expo app, preferably with <a href="https://github.com/react-community/create-react-native-app">create-react-native-app</a>.</p><h3>Set up Google Developer Console</h3><p>We need to set the project up in the Google Developer Console. According to the <a href="https://docs.expo.io/versions/v28.0.0/sdk/google">Expo documentation</a> this is something that they want to automate but can’t do at the moment.</p><blockquote>To use Google Sign In, you will need to create a project on the Google Developer Console and create an OAuth 2.0 client ID. This is, unfortunately, super annoying to do and we wish there was a way we could automate this for you, but at the moment the Google Developer Console does not expose an API.</blockquote><h4>Step 1</h4><p>Go to <a href="https://console.developers.google.com/apis/credentials">Google Developer Console</a> to set up your app. Log in to your Google account and create a new project:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*A8zyNPXT7mGP0JuHYlalYw.png" /><figcaption>Create a new project</figcaption></figure><h4>Step 2</h4><p>Make sure you have your project picked, then click Create Credentials and choose <strong>OAuth client ID</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pwBLCvK0iybtf1COAqgJwQ.png" /></figure><p>You’ll need to set a product name to your app. Do that by pressing the configure consent screen button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wp4u6iZKN_KRzUe9vX-hvQ.png" /><figcaption>Press Configure consent screen button</figcaption></figure><p>Give it a product name and press save:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ib1PYuXozYNr8jethQYoVg.png" /><figcaption>Give it a product name</figcaption></figure><h4>Step 3</h4><p>Pick <strong>Android </strong>for Application type, then open the terminal on your computer and type:</p><pre>openssl rand -base64 32 | openssl sha1 -c</pre><p>Copy the key from the terminal and enter it in the <strong>Signing-certificate fingerprint</strong> text field. <strong>Package name </strong>should be<strong> host.exp.exponent</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PzW2VUI2KYjxDaDHqTs_jQ.png" /><figcaption><em>(This step is different for iPhone. For iPhone, pick the iOS radio button and follow </em><a href="https://docs.expo.io/versions/latest/sdk/google.html#create-an-ios-oauth-client-idselect-ios"><em>these instructions</em></a><em>.)</em></figcaption></figure><p>Clicking Create gives you your <strong>Android Client ID</strong> (you’ll need this in your code later)”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rlCogqkO4QEMj0w2Woss-w.png" /><figcaption>Your Android Client ID</figcaption></figure><h3>The code</h3><p><a href="https://github.com/lingonsaft/google-sign-in-expo-create-react-native-app/blob/master/App.js">Here on Github</a> is all the code conveniently in one file App.js.<br>I will continue with breaking this code down in parts explaining what it does.</p><pre>import React from &quot;react&quot;</pre><pre>import { StyleSheet, Text, View, Image, Button } from &quot;react-native&quot;</pre><pre>import Expo from &quot;expo&quot;</pre><p>This is all the imports that you will need for this example. No need to npm/yarn install anything.</p><pre>export default class App extends React.Component {<br>    constructor(props) {<br>        super(props)<br>        this.state = {<strong>signedIn</strong>: false, <strong>name</strong>: &quot;&quot;, <strong>photoUrl</strong>: &quot;&quot;}<br>    }<br>}</pre><p>Define the state in the constructor. We need to keep track of 3 things.</p><ul><li><strong>signedIn </strong>to keep track if user are logged in or not</li><li><strong>name </strong>the name of the user that google will give us</li><li><strong>photoUrl</strong> the url to the photo that google will give us</li></ul><pre>...<br>signIn = async () =&gt; {<br>    try {<br>      <strong>const result = await Expo.Google.logInAsync({<br>        androidClientId: &quot;YOUR_CLIENT_ID_HERE&quot;,<br>        </strong>//iosClientId: YOUR_CLIENT_ID_HERE,  &lt;-- if you use iOS<br>        <strong>scopes: [&quot;profile&quot;, &quot;email&quot;]<br>      })</strong><br>    } catch (e) {<br>      console.log(&quot;error&quot;, e)<br>    }<br>}</pre><p>(<em>For iOS replace </em><strong><em>androidClientId </em></strong><em>with </em><strong><em>iosClientId </em></strong><em>or use both</em>)</p><p>This function will be called when the user press the sign in button. Replace the string with your <strong>AndroidCliendId</strong> that we got earlier from the Google Developer Console.</p><pre>signIn = async () =&gt; {<br>    try {<br>      const result = await Expo.Google.logInAsync({<br>        androidClientId: androidClientId,<br>        scopes: [&quot;profile&quot;, &quot;email&quot;]<br>      })</pre><pre><strong>      if (result.type === &quot;success&quot;) {<br>        this.setState({<br>          signedIn: true,<br>          name: result.user.name,<br>          photoUrl: result.user.photoUrl<br>        })<br>      } else {<br>        console.log(&quot;cancelled&quot;)<br>      }</strong></pre><pre>} catch (e) {<br>      console.log(&quot;error&quot;, e)<br>    }<br>}</pre><p>Add a check if the login was successful and if it was, set the state accordingly. <em>console.log(result)</em> to see all the data you get from google.</p><pre>...</pre><pre>render() {<br>    return (<br>      &lt;View style={styles.container}&gt;<br>        {<strong>this.state.signedIn</strong> ? (<br>          <strong>&lt;LoggedInPage name={this.state.name} photoUrl={this.state.photoUrl} /&gt;</strong><br>        ) : (<br>          <strong>&lt;LoginPage signIn={this.signIn} /&gt;</strong><br>        )}<br>      &lt;/View&gt;<br>    )<br>  }</pre><p>The render function renders either LoggedInPage or LoginPage component depending on if we set the s<em>ignedIn </em>state to true or false</p><pre>const LoginPage = props =&gt; {<br>  return (<br>    &lt;View&gt;<br>      &lt;Text style={styles.header}&gt;Sign In With Google&lt;/Text&gt;<br>      &lt;Button title=&quot;Sign in with Google&quot; <br>       onPress={() =&gt; props.signIn()} /&gt;<br>    &lt;/View&gt;<br>  )<br>}</pre><p>Create the stateless component <em>LoginPage </em>that we will display if the user is not signed in.</p><pre>const LoggedInPage = props =&gt; {<br>  return (<br>    &lt;View style={styles.container}&gt;<br>      &lt;Text style={styles.header}&gt;Welcome:{props.name}&lt;/Text&gt;<br>      &lt;Image style={styles.image} source={{ uri: props.photoUrl }}/&gt;<br>    &lt;/View&gt;<br>  )<br>}</pre><p>Create the stateless component <em>LoggedInPage </em>that we display when the user is signed in.</p><pre>const styles = StyleSheet.create({<br>  container: {<br>    flex: 1,<br>    backgroundColor: &quot;#fff&quot;,<br>    alignItems: &quot;center&quot;,<br>    justifyContent: &quot;center&quot;<br>  },<br>  header: {<br>    fontSize: 25<br>  },<br>  image: {<br>    marginTop: 15,<br>    width: 150,<br>    height: 150,<br>    borderColor: &quot;rgba(0,0,0,0.2)&quot;,<br>    borderWidth: 3,<br>    borderRadius: 150<br>  }<br>})</pre><p>Final touch! The stylings I’m using.</p><h3>Done!</h3><ul><li>The<a href="https://github.com/lingonsaft/google-sign-in-expo-create-react-native-app"> Github repo</a></li><li>Follow me on <a href="https://twitter.com/Benny_Carlsson">Twitter</a></li><li>More guides on <a href="https://www.youtube.com/c/lingonsaft">YouTube</a></li><li><a href="https://docs.expo.io/versions/latest/sdk/google.html">Expo Documentation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9cac6c392f0e" width="1" height="1" alt=""><hr><p><a href="https://blog.expo.dev/google-sign-in-with-react-native-and-expo-9cac6c392f0e">Google Sign-in with React Native and Expo</a> was originally published in <a href="https://blog.expo.dev/">Exposition</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>