@vunexa/lixa-providers
v0.0.1-alpha.2
Published
Official OAuth provider implementations for Lixa
Maintainers
Readme
@vunexa/lixa-providers
Official OAuth provider implementations for Lixa.
Installation
npm install @vunexa/lixa @vunexa/lixa-providersSupported Providers
- Google - OAuth 2.0 + OpenID Connect
- GitHub - OAuth 2.0
Usage
Google Provider
import { Lixa } from '@vunexa/lixa';
import { GoogleProvider } from '@vunexa/lixa-providers';
const lixa = new Lixa({
providers: {
google: {
provider: new GoogleProvider(),
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
redirectUri: 'https://yourapp.com/auth/google/callback',
scopes: ['openid', 'email', 'profile']
}
}
});
// Generate authorization URL
const state = Lixa.generateRandomState();
const authUrl = lixa.getAuthUrl('google', state);
// Redirect user to authUrl...
// Handle callback
const sessionId = await lixa.handleCallback({
provider: 'google',
code: req.query.code,
state: req.query.state
});GitHub Provider
import { Lixa } from '@vunexa/lixa';
import { GithubProvider } from '@vunexa/lixa-providers';
const lixa = new Lixa({
providers: {
github: {
provider: new GithubProvider(),
clientId: process.env.GITHUB_CLIENT_ID!,
clientSecret: process.env.GITHUB_CLIENT_SECRET!,
redirectUri: 'https://yourapp.com/auth/github/callback',
scopes: ['read:user', 'user:email']
}
}
});Multiple Providers
import { Lixa } from '@vunexa/lixa';
import { GoogleProvider, GithubProvider } from '@vunexa/lixa-providers';
const lixa = new Lixa({
providers: {
google: {
provider: new GoogleProvider(),
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
redirectUri: 'https://yourapp.com/auth/google/callback',
scopes: ['openid', 'email', 'profile']
},
github: {
provider: new GithubProvider(),
clientId: process.env.GITHUB_CLIENT_ID!,
clientSecret: process.env.GITHUB_CLIENT_SECRET!,
redirectUri: 'https://yourapp.com/auth/github/callback',
scopes: ['read:user', 'user:email']
}
}
});Common Scopes
openid- Required for OpenID Connectemail- Access to user's email addressprofile- Access to user's basic profile informationhttps://www.googleapis.com/auth/drive.readonly- Read-only access to Google Drivehttps://www.googleapis.com/auth/calendar.readonly- Read-only access to Google Calendar
Full list of Google OAuth scopes
GitHub
user- Read/write access to profile infouser:email- Read access to user's email addressesread:user- Read-only access to profile inforepo- Full control of private repositoriespublic_repo- Access to public repositoriesgist- Create gistsread:org- Read-only access to organization membership
Full list of GitHub OAuth scopes
Custom Providers
Need to integrate a provider that's not included? You can create your own by implementing the IProvider interface:
import { Lixa, IProvider } from '@vunexa/lixa';
const customProvider: IProvider = {
authorizationEndpoint: 'https://provider.com/oauth/authorize',
tokenEndpoint: 'https://provider.com/oauth/token',
userInfoEndpoint: 'https://provider.com/api/user'
};
const lixa = new Lixa({
providers: {
custom: {
provider: customProvider,
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
redirectUri: 'https://yourapp.com/auth/custom/callback',
scopes: ['read:user']
}
}
});Documentation
For complete documentation, visit the Lixa documentation.
License
MIT
