Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 - oauth2 upgrade #110

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/bump.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out source
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ssh-key: ${{ secrets.DEPLOY_KEY }}

- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: "lts/*"
registry-url: https://registry.npmjs.org/
Expand Down
61 changes: 5 additions & 56 deletions .github/workflows/main.yml
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General CI cleanup. Save CI minutes by running all checks before build

Original file line number Diff line number Diff line change
@@ -1,35 +1,17 @@
name: CI

on: [push]
on: [push, pull_request]

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Use Node LTS
uses: actions/setup-node@v3
with:
node-version: "lts/*"

- name: Install dependencies
uses: bahmutov/npm-install@v1

- name: Build
run: npm run build

typecheck:
name: Typechecker
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Use Node LTS
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: "lts/*"

Expand All @@ -38,42 +20,9 @@ jobs:

- name: Typecheck
run: npm run typecheck

test:
name: Unit and Integration Tests
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Use Node LTS
uses: actions/setup-node@v3
with:
node-version: "lts/*"

- name: Install dependencies
uses: bahmutov/npm-install@v1

- name: Test
run: npm run test -- --ci --coverage --maxWorkers=2

lint:
name: Linter
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Use Node LTS
uses: actions/setup-node@v3
with:
node-version: "lts/*"

- name: Install dependencies
uses: bahmutov/npm-install@v1

- name: Build
run: npm run build

- name: Lint
run: npm run lint
- name: Build
run: npm run build
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: "lts/*"
registry-url: https://registry.npmjs.org/
Expand Down
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"semi": true
"semi": true,
"proseWrap": "always"
}
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Auth0Strategy

The Auth0 strategy is used to authenticate users against an Auth0 account. It extends the OAuth2Strategy.
The Auth0 strategy is used to authenticate users against an Auth0 account. It
extends the OAuth2Strategy.

## Supported runtimes

Expand All @@ -13,7 +14,9 @@ The Auth0 strategy is used to authenticate users against an Auth0 account. It ex

### Create an Auth0 tenant

Follow the steps on [the Auth0 documentation](https://auth0.com/docs/get-started/create-tenants) to create a tenant and get a client ID, client secret and domain.
Follow the steps on
[the Auth0 documentation](https://auth0.com/docs/get-started/create-tenants) to
create a tenant and get a client ID, client secret and domain.

### Create the strategy instance

Expand All @@ -22,18 +25,20 @@ Follow the steps on [the Auth0 documentation](https://auth0.com/docs/get-started
import { Authenticator } from "remix-auth";
import { Auth0Strategy } from "remix-auth-auth0";

type User = { /* fill in*/ };

// Create an instance of the authenticator, pass a generic with what your
// strategies will return and will be stored in the session
export const authenticator = new Authenticator<User>(sessionStorage);

let auth0Strategy = new Auth0Strategy(
const auth0Strategy = new Auth0Strategy(
{
callbackURL: "https://example.com/auth/auth0/callback",
clientID: "YOUR_AUTH0_CLIENT_ID",
clientSecret: "YOUR_AUTH0_CLIENT_SECRET",
domain: "YOUR_TENANT.us.auth0.com",
},
async ({ accessToken, refreshToken, extraParams, profile }) => {
async ({ tokens: { access_token, scope, expires_in, refresh_token }, profile }) => {
// Get the user data from your DB or API using the tokens and profile
return User.findOrCreate({ email: profile.emails[0].value });
},
Expand Down Expand Up @@ -61,9 +66,9 @@ import { redirect, type ActionFunctionArgs } from "@remix-run/node";

import { authenticator } from "~/utils/auth.server";

export let loader = () => redirect("/login");
export const loader = () => redirect("/login");

export let action = ({ request }: ActionFunctionArgs) => {
export const action = ({ request }: ActionFunctionArgs) => {
return authenticator.authenticate("auth0", request);
};
```
Expand All @@ -74,7 +79,7 @@ import { type LoaderFunctionArgs } from "@remix-run/node";

import { authenticator } from "~/utils/auth.server";

export let loader = ({ request }: LoaderFunctionArgs) => {
export const loader = ({ request }: LoaderFunctionArgs) => {
return authenticator.authenticate("auth0", request, {
successRedirect: "/dashboard",
failureRedirect: "/login",
Expand Down
3 changes: 2 additions & 1 deletion config/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Config } from "@jest/types";
// eslint-disable-next-line unicorn/prefer-node-protocol
// eslint-disable-next-line unicorn/import-style
import * as path from "path";
import path from "path";

const config: Config.InitialOptions = {
verbose: Boolean(process.env.CI),
Expand All @@ -10,6 +10,7 @@ const config: Config.InitialOptions = {
resetMocks: false,
setupFilesAfterEnv: ["<rootDir>/config/jest/setup.ts"],
testMatch: ["<rootDir>/test/**/*.test.ts"],
transformIgnorePatterns: ["/node_modules/(?!remix-auth-oauth2)/"],
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v2 is ESM so we need to transpile

transform: {
"\\.[jt]sx?$": [
"babel-jest",
Expand Down
Loading