New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-oauth2

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-oauth2

![npm](https://img.shields.io/npm/v/react-oauth2) ![GitHub](https://img.shields.io/github/license/maxifjaved/react-oauth2) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/react-oauth2) ![npm type definitions](https://img.shields.io/npm/types

latest
Source
npmnpm
Version
2.0.10
Version published
Weekly downloads
27
68.75%
Maintainers
1
Weekly downloads
 
Created
Source

React OAuth2 Social Login

npm GitHub npm bundle size npm type definitions

A modern, lightweight React component library for implementing OAuth2 social login buttons (Google, Facebook) with TypeScript support. Zero dependencies, fully customizable, and built with security in mind.

Features

  • 🚀 Modern React 18+ and TypeScript support
  • 🎨 Customizable button designs following provider guidelines
  • 🔒 Secure OAuth2 implementation
  • 📦 Tiny bundle size (~5KB minified + gzipped)
  • 🌐 Support for multiple providers (Google, Facebook)
  • 💫 Built-in loading and error states
  • ⚡ Zero external dependencies
  • 🔥 Popup-based authentication flow
  • 📱 Mobile-responsive design

Installation

# npm
npm install react-oauth2

# yarn
yarn add react-oauth2

# pnpm
pnpm add react-oauth2

Quick Start

import { FacebookOauth2, GoogleOauth2 } from 'react-oauth2';

function App() {
    const handleCallback = (error: Error, response: OAuthResponse) => {
        if (error) {
            // Handle error
            return;
        }
        const {profile} = response;
        // Handle successful login
    };

  return (
    <div>
      <GoogleOauth2
        clientId="your-google-client-id"
        clientSecret="your-google-client-secret"
        redirectUri="http://localhost:3000/auth/google/callback"
        scope={['openid', 'email', 'profile']}
        callback={handleCallback}
      >
        Continue with Google
      </GoogleOauth2>

      <FacebookOauth2
        clientId="your-facebook-client-id"
        clientSecret="your-facebook-client-secret"
        redirectUri="http://localhost:3000/auth/facebook/callback"
        scope="email,public_profile"
        callback={handleCallback}
      >
        Continue with Facebook
      </FacebookOauth2>
    </div>
  );
}

OAuth Provider Setup

Google Setup

  • Go to the Google Cloud Console
  • Create a new project or select an existing one
  • Navigate to APIs & Services > Credentials
  • Click "Create Credentials" > "OAuth 2.0 Client ID"
  • Configure your OAuth consent screen
  • Add authorized redirect URIs
  • Copy your Client ID and Client Secret

Facebook Setup

  • Go to Facebook Developers
  • Create a new app or select an existing one
  • Add the Facebook Login product
  • Configure OAuth settings
  • Add your redirect URI
  • Copy your App ID and App Secret

API Reference

GoogleButton Props

PropTypeRequiredDescription
clientIdstringYesYour Google OAuth 2.0 client ID
clientSecretstringYesYour Google OAuth 2.0 client secret
redirectUristringYesThe URI to redirect to after authentication
scopestring[]NoArray of permission scopes
callback(error: Error, response: OAuthResponse) => voidYescallback
classNamestringNoCustom CSS class
styleCSSPropertiesNoCustom styles
childrenReactNodeYesButton content

FacebookButton Props

PropTypeRequiredDescription
clientIdstringYesYour Facebook App ID
clientSecretstringYesYour Facebook App Secret
redirectUristringYesThe URI to redirect to after authentication
scopestringNoComma-separated permission scopes
callback(error: Error, response: OAuthResponse) => voidYescallback
classNamestringNoCustom CSS class
styleCSSPropertiesNoCustom styles
childrenReactNodeYesButton content

Advanced Usage

Custom Styling

<GoogleButton
  className="custom-google-button"
  style={{
    backgroundColor: '#4285f4',
    color: 'white',
    padding: '12px 24px',
    borderRadius: '4px',
  }}
>
  <GoogleIcon className="custom-icon" />
  Sign in with Google
</GoogleButton>

Environment Variables

// .env
REACT_APP_GOOGLE_CLIENT_ID=your-google-client-id
REACT_APP_GOOGLE_CLIENT_SECRET=your-google-client-secret
REACT_APP_FACEBOOK_CLIENT_ID=your-facebook-client-id
REACT_APP_FACEBOOK_CLIENT_SECRET=your-facebook-client-secret

TypeScript Usage

import type {OAuthResponse, OAuthError} from 'react-oauth2';

const handleCallback = (error: Error, response: OAuthResponse) => {
    if (error) {
        // Handle error
        return;
    }
    const {profile} = response;
    // Handle successful login
};

Source Code

The full source code for this package is available on GitHub.

Security Considerations

  • Never expose your client secrets in client-side code
  • Use environment variables for sensitive data
  • Implement proper CSRF protection
  • Validate OAuth responses on your backend
  • Use HTTPS for all OAuth endpoints
  • Regularly rotate your client secrets

Browser Support

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Edge (latest)
  • iOS Safari (latest)
  • Android Chrome (latest)

Contributing

We welcome contributions! Please see our Contributing Guide for details.

  • Fork the repository
  • Create your feature branch
  • Commit your changes
  • Push to the branch
  • Create a Pull Request

License

MIT © maxifjaved

Keywords

react, oauth, oauth2, social-login, google-login, facebook-login, react-component, typescript, authentication, social-authentication, google-oauth, facebook-oauth, react18, social-media-login, oauth2-client, react-oauth, social-signin, google-signin, facebook-signin, react-social-login

Made with ❤️ by @maxifjaved

Keywords

react

FAQs

Package last updated on 01 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts