Esempio n. 1
0
def generate():
    """Shows basic usage of the Drive v3 API.
    Prints the names and ids of the first 10 files the user has access to.
    """

    # If modifying these scopes, delete the file token.json.
    SCOPES = ["https://www.googleapis.com/auth/drive"]

    config = get_config_data()
    cfg = pick(config, 'connectors.g_drive')
    token_path = pick(cfg, 'token_path')
    cred_path = pick(cfg, 'credential_path')
    # The file token.json stores the user's access and refresh tokens, and is
    # created automatically when the authorization flow completes for the first
    # time.
    store = file.Storage(token_path)
    creds = store.get()
    if not creds or creds.invalid:
        flow = client.flow_from_clientsecrets(cred_path, SCOPES)
        creds = tools.run_flow(flow, store)
    service = build('drive', 'v3', http=creds.authorize(Http()))

    # Call the Drive v3 API
    results = service.files().list(
        pageSize=10, fields="nextPageToken, files(id, name)").execute()
    items = results.get('files', [])

    if not items:
        print('No files found.')
    else:
        print('Files:')
        for item in items:
            print(u'{0} ({1})'.format(item['name'], item['id']))
Esempio n. 2
0
def generate():
    config = get_config_data()
    cfg = pick(config, 'connectors.trello')
    api_key = pick(cfg, 'api_key')
    api_secret = pick(cfg, 'api_secret')

    util.create_oauth_token(key=api_key, secret=api_secret)
Esempio n. 3
0
    def __init__(self, config):
        self.default_connector = ""
        self.connectors = {}

        self.default_connector = pick(config, 'default_connector')
        if pick(config, 'connectors'):
            for key, connector_cfg in config['connectors'].items():
                if key not in SUPPORTED_CONNECTORS:
                    continue
                converted_key = ConnectorType(key)
                self.connectors[converted_key] = self.create_connector(
                    key, connector_cfg)
Esempio n. 4
0
def generate():
    config = get_config_data()
    cfg = pick(config, 'connectors.slack')

    client_id = pick(cfg, 'client_id')
    client_secret = pick(cfg, 'client_secret')
    oauth_scope = "users:read,users:read.email"
    print("Go to http://localhost:8888/begin_auth")

    app = Flask(__name__)

    @app.route("/begin_auth", methods=["GET"])
    def pre_install():
        return '''
          <a href="https://slack.com/oauth/authorize?scope={0}&client_id={1}">
              Add to Slack
          </a>
      '''.format(oauth_scope, client_id)

    @app.route("/finish_auth", methods=["GET", "POST"])
    def post_install():
        # 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 jsonify(auth_response['access_token'])
        # print('Bot token {}'.format(auth_response['bot']['bot_access_token']))

    app.run(host='0.0.0.0', port=8888)
Esempio n. 5
0
def preprocess():
    global config, default_connector
    config = ConfigHelper.get_config_data()
    default_connector = pick(config, 'default_connector') if 'default_connector' in config else ""