def fetch_twitch_token(code): # on success, session has the token to use ss = get_creds() result = False body_payload = { "client_id": ss["twitch_client_id"], "client_secret": ss["twitch_client_secret"], "grant_type": "authorization_code", "code": code, "redirect_uri": "%s/api/ident/twitchcb" % config.MY_URL, } # redirect_uri may need to match original cb URI (twitch_login_cb) extra_headers = { "Content-Type": "application/x-www-form-urlencoded", } response = requests.post("%s/oauth2/token" % config.TWITCH_API_URL, data=urlencode(body_payload), headers=extra_headers) logging.debug("fetch_twitch_token: headers: %s\n\traw response: %s" % (response.headers, response.text)) try: token_response = json.loads(response.text) if "access_token" in token_response and "refresh_token" in token_response: session["token_response"] = token_response result = True else: logging.warn("NO refresh_token AVAILABLE, BAD AUTH!") except ValueError as e: logging.error("ValueError: " + e) result = False return result
def twitch_login(): ss = get_creds() params = { "client_id": ss["twitch_client_id"], "redirect_uri": "%s/api/ident/twitchcb" % config.MY_URL, "state": True, "response_type": "code", "scope": "openid", # not user_read, id_token, or user_subscriptions # need to request objects for the later userinfo request "claims": json.dumps({ "id_token": {}, "userinfo": { "picture": "null", "preferred_username": "******", } }) } redirect_url = "%s/oauth2/authorize?%s" % (config.TWITCH_API_URL, urlencode(params)) return redirect(redirect_url)
def init_flask(): app_init = Flask(__name__) ss = get_creds() app_init.config["SECRET_KEY"] = ss["session_key"] app_init.config["SESSION_TYPE"] = "redis" Session(app_init) # Start the web session return app_init
def discord_login(): ss = get_creds() params = { "client_id": ss["client_id"], "client_secret": ss["client_secret"], "redirect_uri": "%s/api/ident/cb" % config.MY_URL, "response_type": "code", "scope": "identify" } redirect_url = "%s/oauth2/authorize?%s" % (config.DISCORD_API_URL, urlencode(params)) return redirect(redirect_url)
def fetch_twitch_user(): if "token_response" not in session: return False token = session["token_response"] if "token_type" not in token or "access_token" not in token: return False auth_header_token_type = "" # token request returns "bearer", not "Bearer" sometimes if token["token_type"] in ["bearer", "Bearer"]: auth_header_token_type = "Bearer" # this are attached to session in fetch_twitch_token extra_headers = { "Authorization": "%s %s" % (auth_header_token_type, token["access_token"]), } response = requests.get("%s/oauth2/userinfo" % config.TWITCH_API_URL, headers=extra_headers) logging.debug("fetch_twitch_user: headers: %s\n\traw response: %s" % (response.headers, response.text)) twitch_avatar_url = None twitch_username = None twitch_id = None try: logging.debug("fetch_twitch_user response: %s" % response.text) parsed_response = json.loads(response.text) twitch_id = parsed_response["sub"] twitch_username = parsed_response["preferred_username"] twitch_avatar_url = parsed_response["picture"] except ValueError as e: logging.error("ValueError: " + e) return False ss = get_creds() # TODO: move away from "discord" to a generic auth provider session["discord"] = { "full_username": twitch_username, # TODO: get the right avatar from picture "avatar_url": twitch_avatar_url, "id": twitch_id, "authorized": twitch_id in ss["authorized_twitch_ids"] } return True
def main(): """ Retrieves cell data via Google Sheets API""" # get credentials either cached or requested creds = get_creds() apiService = build('sheets', 'v4', credentials=creds) # Call the Sheets API sheet = apiService.spreadsheets() result = sheet.values().get(spreadsheetId=SPREADSHEET_ID,range=quotesRange).execute() values = result.get('values', []) if not values: print('No data found.') else: for row in values: # Print each each line print(row[0])
def fetch_discord_user(): if "token_response" not in session: return False token = session["token_response"] if "token_type" not in token or "access_token" not in token: return False # TODO: get this from env, not hard coded auth extra_headers = { "Authorization": "%s %s" % (token["token_type"], token["access_token"]), } response = requests.get("%s/users/@me" % config.DISCORD_API_URL, headers=extra_headers) logging.debug("fetch_discord_user: headers: %s\n\traw response: %s" % (response.headers, response.text)) discord_avatar_url = None discord_full_username = None discord_id = None try: logging.debug("fetch_discord_user response: %s" % response.text) parsed_response = json.loads(response.text) discord_avatar_url = "%s/avatars/%s/%s.png" % ( config.DISCORD_CDN_URL, parsed_response["id"], parsed_response["avatar"]) discord_full_username = "******" % (parsed_response["username"], parsed_response["discriminator"]) discord_id = parsed_response["id"] except ValueError as e: logging.error("ValueError: " + e) return False ss = get_creds() session["discord"] = { "full_username": discord_full_username, "avatar_url": discord_avatar_url, "id": discord_id, "authorized": discord_id in ss["authorized_discord_ids"] } return True
import creds import oauth_tweeter import streamLIstener """ check requirements.txt for environment packages testing twitter streaming api with tweepy """ # * Specify file, where credentials are saved and initialize a dics with these creds_file = "credentials.txt" creds = creds.get_creds(creds_file) api = oauth_tweeter.oauth(creds.get("api_key"), creds.get("api_secret"), creds.get("access_token"), creds.get("access_secret")) filter_exp = [ 'bitcoin', 'bitcoinprice', 'bitcoinvalue', 'btc', 'bitcoins', 'bitcoinnews' ] languages = ['en'] streamLIstener.get_stream_listener(api, filter_exp, languages)
#import collectd import json from NovaMetrics import NovaMetrics from CinderMetrics import CinderMetrics from NeutronMetrics import NeutronMetrics import creds c = creds.get_creds() n = NovaMetrics(c['auth_url'], c['username'], c['password'], c['project_name'], c['project_domain_id'], c['user_domain_id']) def test(): data = config_callback() t = read_callback(data) return t def config_callback(): """Receive configuration block""" project_name = c['project_name'] project_domainid = c['project_domain_id'] user_domainid = c['user_domain_id'] auth_url = c['auth_url'] username = c['username'] password = c['password'] interval = 10 testing = False OPENSTACK_CLIENT = {} plugin_conf = {} custom_dimensions = {}