Git Product home page Git Product logo

slack-local-oauth's Introduction

slack-local-oauth: Perform Slack user OAuth flow from the terminal

This demonstrates an end-to-end Slack OAuth flow to get a user access-token from the terminal with no other dependencies besides Python 3.11+ (and optionally OpenSSL).

The script...

  1. runs a local HTTPS OAuth callback server (with a self-signed certificate+key pair generated automatically unless provided)
  2. opens a browser tab to show the Slack OAuth consent screen
  3. handles the OAuth callback and exchanges the auth code for an access token
  4. outputs the access token to stdout

Configuration is done via a .slack.conf file in the current working directory, and the access token is cached by updating the config.

Warning

This script scratches a very particular DevOps scripting itch and is not meant to be very general purpose. It's being shared mainly for the sake of example, since it's not easy to find a self-contained example of the end-to-end OAuth flow.

Usage

Ensure that https://localhost:8103 (or whatever port you want) is listed in your Slack app's allowed OAuth redirect URLs.

Write a .slack.conf file in the current working directory like so, replacing the values with your Slack app identifiers and customizing as desired:

[slack]
client-id = xxxxxxxxxx.xxxxxxxxxxxxx
client-secret = xxxxxxxxxxxxxxxxxxxxxxxx
oauth-callback-port = 8103
scopes = chat:write,channels:read

Then run the script:

./slack_oauth.py

A tab will open in your web browser to confirm the OAuth consent, and then the access token will be written to the terminal via stdout.

The result is cached in .slack.conf so that if you run it again, it doesn't have to re-run the entire flow.

slack-local-oauth's People

Contributors

kkroening avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.