[program-l] python and flask

  • From: "Juan Hernandez" <juanhernandez98@xxxxxxxxx>
  • To: <program-l@xxxxxxxxxxxxx>
  • Date: Thu, 15 Nov 2018 18:28:15 -0800

Hi All,

 

I'm developing an alternative slack client that is far more accessible than
the slack client that is released directly by slack.

 

One issue I'm having and this just because I haven't done much in the past
with Flask, is the instructions say to create a web server using flask for
slack.

 

Here is the instructions at:
https://slackapi.github.io/python-slackclient/auth.html

 

Now, here is my webserver.py file :

 

# controler / webserver.py

 

import os

from flask import Flask, request

from slackclient import SlackClient

import controler.config as cfg

 

app_oauth_scopes = [

    "client",

    "channels:read",

    "channels:write",

    "channels:history",

    "chat:read:user",

    "chat:write:user",

    "dnd:read",

    "dnd:write",

    "dnd:write:user",

    "emoji:read",

    "groups:history",

    "groups:read",

    "groups:write",

    "identity.basic",

    "identity.basic:user",

    "im:history",

    "im:read",

    "im:write",

    "team:read",

    ]

 

client_id = cfg.slack_client_id

client_secret = cfg.slack_client_secret

 

app = Flask(__name__)

 

@app.route("/begin_auth", methods=["GET"])

def preinstall():

    return '''

        <a
href="https://slack.com/oauth/authorize?scope={0}&client_id={1}";>Sign In to
Slack</a>

        '''.format(app_oauth_scopes, client_id)

 

        # end function begin_oauth

 

@app.route("/finish_auth", methods=["GET", "POST"])

def postinstall():

 

    # Retrieve the auth code from the request params

    auth_code = request.args['code']

 

    # An empty string is a valid token for this request

    sc = SlackClient("")

 

    # Request the auth tokens from Slack

    auth_response = sc.api_call(

        "oauth.access",

        client_id=client_id,

        client_secret=client_secret,

        code=auth_code

    )

 

    return auth_response

 

can someone please explain how this is to be used? In the past I've seen
that applications launch a web browser, with a sign into slack button, and
then it takes mme to slack.  How can I duplicate this process? How is this
webserver used?  This is frustrating as my slack client is starting to come
together.  I'm testing with a ttest token, and now I want to release it to a
test group so they can try it out.

 

Thanks for any help.

 

 

 

 

Other related posts: