A collection of social media strategies for remix-auth

Overview

Remix Auth Socials

A collection of Remix Auth strategies for Oauth2 Social logins.

👷 If you are interested in creating one of the planned strategies, or maintaining an existing one reach out! 👷

Current strategies:

  • Discord
  • Github
  • Google
  • Facebook
  • Microsoft

Planned:

  • Twitter
  • Apple
  • LinkedIn
  • Instagram
  • Reddit

Supported runtimes

All strategies will support cloudflare

Runtime Has Support
Node.js ✅
Cloudflare ✅

How to use

The simplicity of this package is that all the included socials behave the same.

Setup your routes

To begin we will set up dynamic routes, that can handle each social on the fly

// app/routes/auth/$provider.tsx
import { ActionFunction, LoaderFunction } from 'remix';
import { authenticator } from '~/auth.server';

export let loader: LoaderFunction = () => redirect('/login');

export let action: ActionFunction = ({ request, params }) => {
  return authenticator.authenticate(params.provider, request);
};
// app/routes/auth/$provider.callback.tsx
import { ActionFunction, LoaderFunction } from 'remix';
import { authenticator } from '~/auth.server';

export let loader: LoaderFunction = ({ request, params }) => {
  return authenticator.authenticate(params.provider, request, {
    successRedirect: '/dashboard',
    failureRedirect: '/login',
  });
};

Now you are free to include social buttons on the login page however you like

// app/routes/login.tsx
import { SocialProvider } from 'remix-auth-socials';

interface SocialButtonProps {
  provider: SocialProvider,
  label: string
}

const SocialButton: React.FC<SocialButtonProps> = ({ provider, label }) => (
  <Form action={`/auth/${provider}`} method="post">
    <button>{label}</button>
  </Form>
);

export default function Login() {
  return (
    <SocialButton provider={SocialProvider.DISCORD} label="Login with Discord" />
    <SocialButton provider={SocialProvider.GITHUB} label="Login with Github" />
    <SocialButton provider={SocialProvider.GOOGLE} label="Login with Google" />
    <SocialButton provider={SocialProvider.FACEBOOK} label="Login with Facebook" />
    <SocialButton provider={SocialProvider.MICROSOFT} label="Login with Microsoft" />
  );
}

Create the strategy instance

For each social you want to use, you must initialise it in your auth.server.ts file.

// app/server/auth.server.ts
import { GoogleStrategy, FacebookStrategy, SocialProvider } from "remix-auth-socials";
import { findOrCreateOauth2User } from "./db.server.ts";

// Create an instance of the authenticator, pass a generic <User> type which the
// strategies will return (this will be stored in the session)
export let authenticator = new Authenticator<User>(sessionStorage, { sessionErrorKey });

authenticator.use(new GoogleStrategy(
  {
    clientID: "YOUR_CLIENT_ID",
    clientSecret: "YOUR_CLIENT_SECRET",
    callbackURL: `https://example.com/auth/${SocialProvider.GOOGLE}/callback`;
  },
  async ({ profile }) => {
    return findOrCreateOauth2User(profile);
  }
));

authenticator.use(new FacebookStrategy(
  {
    clientID: "YOUR_CLIENT_ID",
    clientSecret: "YOUR_CLIENT_SECRET",
    callbackURL: `https://example.com/auth/${SocialProvider.FACEBOOK}/callback`;
  },
  async ({ profile }) => {
    return findOrCreateOauth2User(profile);
  }
));

TODO: Create readme doc for each strategy to show options and link here

Comments
  • GoogleStrategy should allow custom scopes

    GoogleStrategy should allow custom scopes

    Describe the bug

    Right now, the Google Strategy only allows for the "openid", "profile" & "email" scopes, however, there are many custom scopes that can be used with Google such as "https://www.googleapis.com/auth/business.manage" or "https://www.googleapis.com/auth/plus.business.manage". I propose changing the GoogleScope type to a simple string.

    opened by agcty 2
  • DiscordStrategy is not calling verify function

    DiscordStrategy is not calling verify function

    Describe the bug

    When using the DiscordStrategy, the verify function should be called after the authentication is completed. However, when checking the session data, it only returns something called "oauth2:state" with the according state that was passed to discord. When trying to log something in the verify function, nothing is being printed out.

    Your Example Website or App

    https://github.com/mezodev0/shishabot-web

    Steps to Reproduce the Bug or Issue

    1. Create an Application via https://discord.com/developers/applications
    2. Copy paste .env.example
    3. Fill out values
    4. Start project
    5. Click the link to the login page
    6. Click on the login button
    7. Authenticate via Discord

    Expected behavior

    I expected the discord user to be returned, but I am getting nothing.

    Platform

    • OS: Ubuntu Linux
    • Browser: Firefox
    opened by mezodev0 1
  • docs: Updated imports to work for latest remix version

    docs: Updated imports to work for latest remix version

    Since Remix v1.4 they changed the imports. This update changes the snippets in the readme to make it compliant again. Also added an invariant to make typescript happy.

    opened by lajtmaN 1
  • Server crash on rate limits from auth provider

    Server crash on rate limits from auth provider

    Describe the bug

    When GitHub slaps rate limits on a user, the attempt to fetch their profile doesn't return a profile, and the code crashes.

    return value: {
      message: 'API rate limit exceeded for user ID 9287.',
      documentation_url: 'https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting'
    }
    
    TypeError: Cannot read properties of undefined (reading 'toString')
        at GitHubStrategy.userProfile (/Users/isaacs/dev/tierdev/tierweb/node_modules/remix-auth-socials/build/strategies/github.js:45:25)
        at runMicrotasks (<anonymous>)
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
        at GitHubStrategy.authenticate (/Users/isaacs/dev/tierdev/tierweb/node_modules/remix-auth-oauth2/build/index.js:113:23)
        at Object.callRouteLoader (/Users/isaacs/dev/tierdev/tierweb/node_modules/@remix-run/node/node_modules/@remix-run/server-runtime/data.js:77:14)
        at handleResourceRequest (/Users/isaacs/dev/tierdev/tierweb/node_modules/@remix-run/node/node_modules/@remix-run/server-runtime/server.js:453:14)
        at requestHandler (/Users/isaacs/dev/tierdev/tierweb/node_modules/@remix-run/node/node_modules/@remix-run/server-runtime/server.js:42:18)
        at /Users/isaacs/dev/tierdev/tierweb/node_modules/@remix-run/express/server.js:39:22
    

    Your Example Website or App

    sorry, no time to do this, just wrapped in a try/catch for now, reporting so it doesn't get forgotten entirely

    Steps to Reproduce the Bug or Issue

    1. Implement a site that uses log in with GitHub
    2. Repeatedly log in and out a bunch of times (cuz, ya know, you're developing a website, it's what you do, or maybe just being a weird user.)
    3. Observe server crash.

    Expected behavior

    Because this throw happens in the app/routes/auth/$provider.callback.tsx route, it's outside the context of an ErrorBoundary or CatchBoundary. I would expect that it would at least log the error and redirect to the failureRedirect, or perhaps make the error available to the failureRedirect on the query string or something?

    Screenshots or Videos

    No response

    Platform

    • OS: any, logging in with GitHub
    • Browser: all browsers (safari and chrome tested)

    Additional context

    $ npm ls | grep remix | grep auth 
    ├── [email protected]
    ├── [email protected]
    
    opened by isaacs 1
  • The README is not up to date with the code

    The README is not up to date with the code

    Hi! Thanks for your efforts with this project!

    I noticed that the README code examples do not match the actual code that is needed.

    Some examples:

    • References to SocialProvider should be SocialsProvider
    • Imports for ~/auth.server should be for ~/server/auth.server
    • login.tsx is missing enclosing jsx tag
    • auth.server.ts is missing required imports and is referencing non-existant code

    I'll try to get this working, then I can supply a PR (only started with remix 1 hour ago 😅)

    opened by pal 1
  • Idea: Import strategies from other packages if they exists

    Idea: Import strategies from other packages if they exists

    A few of the strategies here are already in other packages. I think if someone already created the individual package of some of them it would be useful to re-export them from remix-auth-socials so you don't need to maintain a copy of the strategy, and while most strategies are probably not going to change a lot if a bug was found in one of them it can be fixed in a single place.

    Some strategies already published independently:

    • https://github.com/sergiodxa/remix-auth-github
    • https://github.com/JonnyBnator/remix-auth-discord
    • https://github.com/pbteja1998/remix-auth-google
    • https://github.com/juhanakristian/remix-auth-microsoft

    There's also https://github.com/chadelofson/remix-auth-facebook but it's not implemented yet.

    opened by sergiodxa 1
  • Add Google hd and login_prompt params

    Add Google hd and login_prompt params

    Allows using the hd and login_prompt parameters to optimize the accounts that are shown on the Google OAuth consent screen. These parameters are documented here: https://developers.google.com/identity/protocols/oauth2/openid-connect

    npm run lint did not pass, but errors were in the Facebook strategy which this PR did not touch.

    opened by katlyn 0
  • Facebook Strategy: Include the profile picture in the payload

    Facebook Strategy: Include the profile picture in the payload

    Hi there,

    It looks like the profile picture field is part of the default fields (without requesting further permissions) so with this PR, this is included to the response following the same pattern used in the Google strategy.

    Finally, here's another example of next-auth including the profile picture.

    opened by manosim 0
  • add github ISSUE_TEMPLATE files

    add github ISSUE_TEMPLATE files

    What is the change?

    1. add bug_report.md to bug-report.yml to enable Github's form based issue template
      • https://youtu.be/qQE1BUkf2-s?t=23
    2. add config.yml file to help direct users to the helpful pages

    Motivation

    • encourage's bug reporter's to put more care into their bug report before submission
    • this may help maintainer's receive more detailed & higher quality bug report's
    • adds helpful tips for user's during the process of creating a bug/issue report

    Demo of Change

    this PR is similar to this one I created here for another repo recently

    • https://github.com/antvis/G6/blob/master/.github/ISSUE_TEMPLATE/bug_report.yml
    opened by cliffordfajardo 0
  • LinkedIn Strategy (another package)

    LinkedIn Strategy (another package)

    Hi, how are you?

    I'm just passing here to show you I made a package for LinkedIn Strategy. I red your message in this other issue of yours and you have valid points.

    I documented the code, made tests and export some other things among the main class. Here is the source code to look at it

    Let me know how you see it, if you consider i am missing something for you so you can re-export from there. Feedback and suggestions are welcome.

    Have a nice Saturday!

    opened by Lzok 4
Releases(v2.0.0)
Owner
Tom Rowe
I refactor code 10 times before touching the keyboard... it's a superpower I wish I had for bio's
Tom Rowe
Remix Stack for deploying to Vercel with remix-auth, Planetscale, Radix UI, TailwindCSS, formatting, linting etc. Written in Typescript.

Remix Synthwave Stack Learn more about Remix Stacks. npx create-remix --template ilangorajagopal/synthwave-stack What's in the stack Vercel deploymen

Ilango 56 Dec 25, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Auth-Form-Design - Beautiful Auth Form Designed using React 🥰.

?? Auth Form Design ?? Features 1. Check Your Password Strength 2. Can Use Suggested Password 3. Enjoy Responsive Design Getting Started with Create R

Samarpan Dasgupta 2 Dec 24, 2022
Firebase adepter auth process with custom token example in Next Auth

Firebase adepter auth process with custom token example in Next Auth Example of a firebase adapter that works with firebase authentication. A firebase

Low Front 10 Oct 14, 2022
FACEIT (OAuth2) authentication strategies for Passport.

passport-faceit FACEIT is a trademark or registered trademark of FACEIT LIMITED in the U.S. and/or other countries. "@ambergg/passport-faceit" is not

Amber.gg 5 Oct 26, 2022
It's a set of common utility strategies to work with responsive styles with Flutter and CSS in JS

@skynexui/responsive_stylesheet You don't need to be worried just because you have to support multiple screens ?? ?? ?? ?? It's a set of common utilit

SkynexUI 40 Oct 26, 2022
Detect F12 open console, protect web static resources, support redirect, rewrite, callback strategies.

console-ban Detect F12 open browser console. protect web site static resources, support redirect, rewrite, custom callback strategies. Language: Engli

Yingci 623 Dec 26, 2022
A Remix Auth strategy for working with forms.

FormStrategy A Remix Auth strategy to work with any form. Supported runtimes Runtime Has Support Node.js ✅ Cloudflare ✅ How to use This Strategy gives

Sergio Xalambrí 40 Jan 2, 2023
Remix Auth plugin for Twitter OAuth 1.0a

Remix Auth Twitter Remix Auth plugin for Twitter OAuth 1.0a. Supported runtimes Runtime Has Support Node.js ✅ Cloudflare ✅ Demo Try out live demo (sou

na2hiro 13 Dec 31, 2022
Sharerbox - Free, minimalist and lightweight JavaScript-based social-media sharer for websites

Sharerbox Free minimalist and lightweight JavaScript-based social-media sharer for websites. Version: 0.8.1 Description SharerBox is a free, minimalis

Juan Astudillo 3 Aug 22, 2022
Lets you add a character to Hacker News links to add social media and OpenGraph previews for sharing on things like Slack or Twitter.

news.ycombinator1.com Lets you add a character to Hacker News links to add social media and OpenGraph previews for sharing on things like Slack or Dis

Ian Langworth ☠ 38 Sep 18, 2022
A health-focused app for users to be able to track workouts and nutritional data with a social media component to inspire friendly competition among the users.

A health-focused app for users to be able to track workouts and nutritional data with a social media component to inspire friendly competition among the users.

Jon Jackson 3 Aug 26, 2022
Chrome extension for replacing addictive and annoying features of various social media sites with inspirational quotes.

Saner Social Media Chrome extension for replacing addictive and annoying features of various social media sites with inspirational quotes. Saner Socia

Tobi Dalhof 9 Oct 4, 2022
Social media platform that hosts community-driven challenges where everyone can play and compete

Komo A social media platform that hosts community-driven challenges where everyone can play and compete. How To Install Komo TBA Preview Home Screen A

null 2 Jun 13, 2022
Updog is an open-source social media webapp intended to allow everyday people to share their thoughts in a welcoming community.

SE701-Updog Updog is an open-source social media webapp intended to allow everyday people to share their thoughts in a welcoming community. This proje

SE 701 Team 2 UoA 14 Apr 18, 2022
Software for the next generation of social media. https://gitlab.com/soapbox-pub/soapbox-fe

Soapbox FE Soapbox FE is a frontend for Mastodon and Pleroma with a focus on custom branding and ease of use. It's part of the Soapbox project. Try it

Soapbox 52 Dec 30, 2022