@sedge-hq/oauth
v0.2.1
Published
OAuth sign-in for sedge: Google, Microsoft and any other provider, for channels and signals to share.
Maintainers
Readme
@sedge-hq/oauth
OAuth sign-in for sedge, the always-on agent: sign in once to Google, Microsoft or another provider, and let several channels and signals use the account.
A kind asks for an account with the kit's account(...) setting, naming the providers it takes,
each with the scopes it needs:
import { account } from '@sedge-hq/kit';
import { google, microsoft, SCOPES } from '@sedge-hq/oauth';
settings: {
login: account('Your Google or Microsoft account', [
google([SCOPES.gmail]),
microsoft([SCOPES.outlookImap, SCOPES.outlookSmtp]),
]),
}
// later: const token = await settings.login.token();sedge runs the sign-in in the browser (the authorization-code flow with PKCE, coming back to a page on this machine), keeps the refresh token in the keychain, and refreshes access tokens before they expire. A token that comes with no lifetime and no refresh token (GitHub's) is kept in the keychain as it is. Kinds only ever get access tokens, for the scopes they declared.
The providers here:
google,microsoft: mail, calendars and the rest of their APIs.github: an OAuth app of your own, with the callback URLhttp://127.0.0.1/(GitHub lets the port differ). It wants the client secret even with PKCE. The account is named by its login.slack: as the user, not a bot. Slack lets an app that signs in on a computer (PKCE, coming back tohttp://localhost:53682/) ask only for user scopes, which it reads fromauthed_user. The account is named by the user and workspace.
SCOPES names what kinds commonly ask for (gmail, githubRepo, slackChatWrite …).
defineProvider adds any OAuth 2 provider: its endpoints and extra sign-in parameters, PKCE, the
redirect host (loopback) and a fixed port when the provider matches it exactly, how early to
refresh (refreshBefore), how long a token lasts when it doesn't say (lifetime), whether a
refresh asks for the scopes again (scopeOnRefresh), the sign-in parameter for scopes and their
separator (scopeParam, scopeSeparator), where the token sits in the answer (tokenPath), and an
identity address that says who signed in when there's no ID token. Granted scopes are read
whether the provider separates them with spaces or commas.
Accounts and sign-in · MIT
