@iracing-data/oauth-client
v0.0.1-alpha.2
Published
An OAuth2.0 client for iRacing, as defined by the spec at https://oauth.iracing.com/oauth2/book/introduction.html
Readme
@iracing-data/oauth-client
An OAuth2.0 client for iRacing, as defined by the spec at https://oauth.iracing.com/oauth2/book/introduction.html
Installation
npm install @iracing-data/oauth-client
yarn add @iracing-data/oauth-client
pnpm i @iracing-data/oauth-clientUsage
See oauth-example for usage example.
import { OAuthClient } from "@iracing-data/oauth-client"
const client = new OAuthClient({
clientMetadata: {
clientId: process.env.IRACING_AUTH_CLIENT_ID!
redirectUri: "http://localhost:3000/oauth/callback/iracing"
scopes: "iracing.auth iracing.profile"
},
stateStore: new InMemoryStore()
});
// Invoke authorize and redirect to the provided URL
const { url } = await client.authorize();
redirect(url)
// Some time passes and the callback is invoked...
const params = new URLSearchParams(req.url.split("?")[1]);
const { access_token } = await client.callback(params);
// Do stuff with the token...