Intro
Settings - Configure a Project
1. Google APIs >>> 프로젝트 생성
2. OAuth consent screen
3. Credentials > Create Credentials > OAuth client ID > Application type : Web application
Resource 서버에 Client를 등록해서 등록 번호와 등록 비밀번호를 발급 받음.
Any application that uses OAuth 2.0 to access Google APIs must have authorization credentials that identify the application to Google's OAuth 2.0 server.
After configuration is complete, take note of the client ID that was created. You will need the client ID to complete the next steps. (A client secret is also created, but you need it only for server-side operations.)
You must include the Google Platform Library on your web pages that integrate Google Sign-In.
Specify the client ID you created for your app in the Google Developers Console with the
google-signin-client_id
meta element.
// index.html
<head>
<!-- Google Sign-in -->
<script src="https://apis.google.com/js/platform.js" async defer></script>
<meta name="google-signin-client_id" content="YOUR_CLIENT_ID.apps.googleusercontent.com">
<!-- End Google Sign-in -->
</head>
To create a Google Sign-In button with custom settings, add an element to contain the sign-in button to your sign-in page, write a function that calls
signin2.render()
with your style and scope settings, and include thehttps://apis.google.com/js/platform.js
script with the query stringonload=YOUR_RENDER_FUNCTION
.
<div class="g-signin2" data-onsuccess="onSignIn"></div>
// <button onClick={onSignIn}>Google Sign In</button>
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
console.log('Name: ' + profile.getName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
}