Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/willin/remix-auth-sso
A Simple SSO Auth Strategy For Willin SSO
https://github.com/willin/remix-auth-sso
auth remix sso
Last synced: 3 months ago
JSON representation
A Simple SSO Auth Strategy For Willin SSO
- Host: GitHub
- URL: https://github.com/willin/remix-auth-sso
- Owner: willin
- License: apache-2.0
- Created: 2023-11-17T07:43:30.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-05T06:18:36.000Z (about 1 year ago)
- Last Synced: 2024-04-14T00:59:14.574Z (10 months ago)
- Topics: auth, remix, sso
- Language: TypeScript
- Homepage: https://github.com/willin/sso
- Size: 73.2 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# SSOStrategy
The SSO strategy is used to authenticate users against a SSO account. It extends the OAuth2Strategy.
## Supported runtimes
| Runtime | Has Support |
| ---------- | ----------- |
| Node.js | ✅ |
| Cloudflare | ✅ |## Usage
### Create an OAuth application
Follow the steps on [the SSO documentation](https://github.com/willin/sso) to create a new application and get a client ID and secret.
### Create the strategy instance
```ts
import { SSOStrategy } from 'remix-auth-sso';let ssoStrategy = new SSOStrategy(
{
clientID: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
callbackURL: 'https://example.com/auth/sso/callback'
},
async ({ accessToken, extraParams, profile }) => {
// Get the user data from your DB or API using the tokens and profile
return profile;
}
);authenticator.use(ssoStrategy);
```### Setup your routes
```tsx
// app/routes/login.tsx
export default function Login() {
return (
Login with SSO
);
}
``````tsx
// app/routes/auth.sso.tsx
import type { ActionArgs } from '@remix-run/node';
import { redirect } from '@remix-run/node';
import { authenticator } from '~/auth.server';export async function loader() {
return redirect('/login');
}export async function action({ request }: ActionArgs) {
return authenticator.authenticate('sso', request);
}
``````tsx
// app/routes/auth.sso.callback.tsx
import type { LoaderArgs } from '@remix-run/node';
import { authenticator } from '~/auth.server';export async function loader({ request }: LoaderArgs) {
return authenticator.authenticate('sso', request, {
successRedirect: '/dashboard',
failureRedirect: '/login'
});
}
```