Giter VIP home page Giter VIP logo

slack-python-oauth-example's Introduction

Slack Python OAuth Example

This repo contains a sample app for doing OAuth with Slack. It uses the python-slackclient and python-slack-events-api. It has been tested on python 3.7.5.

I recommend using ngrok for local development of slack apps. Checkout this guide for setting it up.

Install dependencies

pip3 install slackclient
pip3 install slackeventsapi
pip3 install flask

Setup enviroment variables

This app requires you setup a few enviroment variables. You can get these values by navigating to your app's BASIC INFORMATION Page.

export SLACK_CLIENT_ID = YOUR_SLACK_CLIENT_ID
export SLACK_CLIENT_SECRET = YOUR_SLACK_CLIENT_SECRET
export SLACK_SIGNING_SECRET = YOUR_SLACK_SIGNING_SECRET

You also need to setup FLASK_APP enviroment variable so flask run knows what to run. This should point to this repos app.py.

export FLASK_APP=app.py

Run the App

Start the app by running the following command

flask run

This will start the app on port 5000.

Now lets start ngrok so we can access the app on an external network and create a redirect url for OAuth and a request url for events.

ngrok http 5000

This should output a forwarding address for http and https. Take note of the https one. It should look something like the following:

Forwarding   https://3cb89939.ngrok.io -> http://localhost:5000

Go to your app on https://api.slack.com/apps and navigate to your apps OAuth & Permissions page. Under Redirect URLs, add your ngrok forwarding address with the /finish_auth path appended. ex:

https://3cb89939.ngrok.io/finish_auth

Now go to Event Subscriptions and enable events. For the Request URL, pass your ngrok forwarding address with /slack/events path appended. ex:

https://3cb89939.ngrok.io/slack/events

While you are in Event Subscriptions, add the member_joined_channel event as the app uses it to send a direct message.

Everything is setup. Go to http:localhost:5000/begin_auth in your browser to start the OAuth install flow for you app!

slack-python-oauth-example's People

Contributors

stevengill avatar

Watchers

James Cloos 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.