authProvider
functionDeclare a sign-in provider for a service this mod talks to. Put the result in the mod's `auth` array. From then on any mod, this one included, gets a token by calling `ctx.auth.getSession(id, scopes, { createIfNone: true })`. That is the consuming side. This is the producing side, and you only write it for a service the host does not already cover. The three callbacks split cleanly: `getSessions` is the silent path and must never prompt, `createSession` is the interactive path and is the only one that may, `removeSession` cleans up.
Import
import { authProvider } from '@modular/sdk';Notes
- example
- ```ts authProvider({ id: 'my-service', label: 'My Service', getSessions: async (scopes, options, ctx) => sessionsFor(await ctx.secrets.get('token')), createSession: async (scopes, options, ctx) => { const token = await ctx.prompt.input({ title: 'API token', password: true }); await ctx.secrets.store('token', requireToken(token)); return sessionFor(token); }, removeSession: async (sessionId, ctx) => ctx.secrets.delete('token'), }); ```
- category
- Authoring