Package Exports
- @svelte-dev/auth-sso
- @svelte-dev/auth-sso/build/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@svelte-dev/auth-sso) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
svelte-auth-sso strategy
The SSO strategy is used to authenticate users against a SSO account. It extends the OAuth2Strategy.
Supported runtimes
| Runtime | Has Support |
|---|---|
| Node.js | ✅ |
| Cloudflare | ✅ |
| Vercel | ✅ |
Usage
Create an OAuth application
Follow the steps on the SSO documentation to create a new application and get a client ID and secret.
Create the strategy instance
import { SSOStrategy } from '@svelte-dev/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
export default function Login() {
return (
<form action='/auth/sso' method='post'>
<button>Login with SSO</button>
</form>
);
}// routes/auth/sso/+server
import { authenticator } from '~/auth.server';
import type { RequestHandler } from './$types';
export const POST: RequestHandler = async (event) => {
return authenticator.authenticate('sso', event);
};// routes/auth/sso/callback/+server
import { authenticator } from '~/auth.server';
import type { PageServerLoad } from './$types';
export const load: PageServerLoad = async ({ event }) => {
return authenticator.authenticate('sso', event, {
successRedirect: '/dashboard',
failureRedirect: '/login'
});
};赞助 Sponsor
维护者 Owner: Willin Wang
如果您对本项目感兴趣,可以通过以下方式支持我:
Donation ways:
- Github: https://github.com/sponsors/willin
- Paypal: https://paypal.me/willinwang
- Alipay or Wechat Pay: QRCode
许可证 License
Apache-2.0