Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/khrj/slack-oauth
Setup the OAuth flow for Slack apps easily. Deno port of @slack/oauth
https://github.com/khrj/slack-oauth
deno oauth slack slack-api
Last synced: 1 day ago
JSON representation
Setup the OAuth flow for Slack apps easily. Deno port of @slack/oauth
- Host: GitHub
- URL: https://github.com/khrj/slack-oauth
- Owner: khrj
- License: mit
- Created: 2021-02-10T15:13:56.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-07-12T13:36:08.000Z (about 3 years ago)
- Last Synced: 2024-10-02T00:20:39.123Z (1 day ago)
- Topics: deno, oauth, slack, slack-api
- Language: TypeScript
- Homepage: https://deno.land/x/slack_oauth
- Size: 80.1 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
### Note on Compatiblity
This is module is mostly compatible with its [node
counterpart](https://www.npmjs.com/package/@slack/oauth). However,
`InstallProvider` does not contain a `handleCallback` function taking request
and response handlers. Instead, it has a `handle` function which takes a `code`
and a `state` and does not handle responding and returns a promise which
resolves / rejects to the default HTML for successes / errors, which you can
then respond with or override. This is to maximize compatiblity with various
Deno HTTP servers.## Usage
### Handling requests
The following is an example of handling a request using [Oak](https://github.com/oakserver/oak) as the HTTP server
```ts
import "https://deno.land/x/[email protected]/load.ts"import { nanoid } from "https://deno.land/x/[email protected]/mod.ts"
import { Application, Router } from "https://deno.land/x/oak/mod.ts"
import { InstallProvider } from "https://deno.land/x/[email protected]/mod.ts"// initialize the installProvider
const installer = new InstallProvider({
clientId: Deno.env.get("SLACK_CLIENT_ID")!,
clientSecret: Deno.env.get("SLACK_CLIENT_SECRET")!,
stateSecret: nanoid(),
})const router = new Router()
router.get("/", async (ctx) => {
ctx.response.redirect(
await installer.generateInstallUrl({
scopes: ["chat:write"],
}),
)
})router.get("/slack/oauth_redirect", async (ctx) => {
const code = ctx.request.url.searchParams.get("code")
const state = ctx.request.url.searchParams.get("state")if (!code || !state) {
ctx.response.status = 401
ctx.response.body = "Unauthorized - Missing code or state"
return
}try {
const successMessage = await installer.handle(code, state)
ctx.response.status = 200
ctx.response.body = successMessage
} catch (e) {
ctx.response.status = 500
ctx.response.body = e.message
}
})const app = new Application()
app.use(router.routes())
app.use(router.allowedMethods())
await app.listen({ port: 8000 })
```### Authorization
You can use the the `installer.authorize()` function to fetch data that has been saved in your installation store.
```ts
import { InstallProvider } from "https://deno.land/x/[email protected]/mod.ts"
const installer = new InstallProvider({
clientId: Deno.env.get("SLACK_CLIENT_ID")!,
clientSecret: Deno.env.get("SLACK_CLIENT_SECRET")!,
stateSecret: nanoid(),
})const result = await installer.authorize({ teamId: "my-team-ID" })
console.log(result)
```## API
- Methods are almost identical to the [node @slack/oauth](https://www.npmjs.com/package/@slack/oauth) (see [Note on Compatiblity](#note-on-compatiblity))
- Generated docs are available at https://doc.deno.land/https/deno.land/x/[email protected]/mod.ts## Supporters
[![Stargazers repo roster for @khrj/slack-oauth](https://reporoster.com/stars/khrj/slack-oauth)](https://github.com/khrj/slack-oauth/stargazers)
[![Forkers repo roster for @khrj/slack-oauth](https://reporoster.com/forks/khrj/slack-oauth)](https://github.com/khrj/slack-oauth/network/members)
## Related
- [Deno Slack SDK](https://github.com/slack-deno/deno-slack-sdk)
- [Deno modules](https://github.com/khrj/deno-modules)