コード例 #1
0
ファイル: moneybot.py プロジェクト: kingdavid6336/moneybot
 def auth(self, sandbox=False):
     if sandbox:
         self.api = Bitreserve(host='api-sandbox.bitreserve.org')
     else:
         self.api = Bitreserve()
     pat = auth.get('pat', None)
     user = auth.get('user', None)
     password = auth.get('password', None)
     if pat:
         self.api.auth_pat(pat)
     elif user and password:
         self.api.auth(user, password)
コード例 #2
0
ファイル: moneybot.py プロジェクト: marado/moneybot
 def auth(self, sandbox=False):
     if sandbox:
         self.api = Bitreserve(host='api-sandbox.bitreserve.org')
     else:
         self.api = Bitreserve()
     pat = auth.get('pat', None)
     user = auth.get('user', None)
     password = auth.get('password', None)
     if pat:
         self.api.auth_pat(pat)
     elif user and password:
         self.api.auth(user, password)
コード例 #3
0
ファイル: moneybot.py プロジェクト: jneves/moneybot
 def auth(self, sandbox=False):
     if sandbox:
         self.api = Bitreserve(host="api-sandbox.bitreserve.org")
     else:
         self.api = Bitreserve()
     pat = auth.get("pat", None)
     user = auth.get("user", None)
     password = auth.get("password", None)
     if pat:
         self.api.auth_pat(pat)
     elif user and password:
         self.api.auth(user, password)
コード例 #4
0
ファイル: profiles.py プロジェクト: kznmft/Axtell
def stackexchange(auth_token):
    user = requests.get(
        'https://api.stackexchange.com/2.2/me',
        params={
            'site': 'codegolf',
            'filter':
            '!)RwcIFN1JaCrhVpgyYeR_oO*',  # Constant obtained from SE API explorer
            'access_token': auth_token,
            'key': auth.get('stackexchange.com').get('key')
        }).json().get('items')[0]

    display_name = html_unescape(user.get('display_name'))

    return user.get('user_id'), {
        'name': display_name,
        'avatar': user.get('profile_image'),
        'email': None,
        'identifier': display_name
    }
コード例 #5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from word import Kindle, Text, Input, Subs
from config import sources, auth
from service import Lingualeo
import sys
import traceback

email = auth.get('email')
password = auth.get('password')

try:
    export_type = sys.argv[1]
    if export_type == 'text':
        if len(sys.argv) == 3:
            source = sys.argv[2]
        else:
            source = sources.get('text')
        handler = Text(source)
    elif export_type == 'kindle':
        handler = Kindle(sources.get('kindle'))
    elif export_type == 'input':
        handler = Input(sys.argv[2:])
    elif export_type == 'subs':
        handler = Subs(sys.argv[2:])
    else:
        raise Exception('unsupported type')

    handler.read()

    lingualeo = Lingualeo(email, password)
コード例 #6
0
ファイル: auth.py プロジェクト: kznmft/Axtell
def set_user_oauth(code, provider, client_side=False, auth_opts={}):
    """
    Logs in an OAuth redirect request given the `provider` describing the type
    """

    oauth_provider = oauth_config.get(provider, None)
    if oauth_provider is None:
        return abort(400)

    oauth_callback = oauth_provider.get('token')
    oauth_login = oauth_provider.get('auth')
    oauth_provider_identifier = provider

    oauth_id = oauth_data.get(oauth_provider_identifier).get('client-id')
    oauth_secret = oauth_data.get(oauth_provider_identifier).get(
        'client-secret')

    try:
        # Get the auth key. By polling the provider we both validate
        # the login request and now are able to submit requests as
        # users of the provider.
        access_token_response = requests.post(oauth_callback,
                                              data={
                                                  'code':
                                                  code,
                                                  'redirect_uri':
                                                  canonical_host +
                                                  url_for('auth_login_oauth'),
                                                  'client_id':
                                                  oauth_id,
                                                  'client_secret':
                                                  oauth_secret,
                                                  'grant_type':
                                                  'authorization_code'
                                              },
                                              headers={
                                                  'Accept': 'application/json'
                                              }).json()
    except Exception as error:
        if bugsnag.configuration.api_key is not None:
            bugsnag.notify(error, meta_data={'oauth': {'provider': provider}})

        # Errors mean we couldn't get access key
        return render_error('Failed to connect to OAuth provider.'), 403

    try:
        auth_key = access_token_response['access_token']
    except Exception as error:
        if bugsnag.configuration.api_key is not None:
            bugsnag.notify(error,
                           meta_data={
                               'oauth': {
                                   'provider': provider,
                                   'data': access_token_response
                               }
                           })

        # Errors mean we couldn't get access key
        return render_error(
            'Could not obtain OAuth access token from OAuth provider.'), 403

    is_append_flow = auth_opts.get('append', False)

    # If we're client-side we'll stop here UNLESS we are appending
    if client_side and not is_append_flow:
        return auth_key

    try:
        # Get identity key, this is something that allows us
        # to uniquely identify the user.
        # The profile['identification'] is a user-readable string.
        oauth_identity, profile = oauth_login(auth_key)
    except Exception as error:
        if bugsnag.configuration.api_key is not None:
            bugsnag.notify(error, meta_data={'oauth': {'provider': provider}})

        # If we get here that means we could not get profile
        # this is our fault since we validated
        return render_error(
            'Could not obtain OAuth profile using provider implementation.'
        ), 500

    if 'identifier' not in profile:
        return render_error('Could not obtain identifier'), 400

    # Model instance for the token
    # Links together the provider, provider's ID, and our user ID
    token = UserAuthToken(auth_method=AuthTokenType.OAUTH,
                          issuer=oauth_provider_identifier,
                          identity=oauth_identity,
                          identifier=profile.get('identifier'))

    return get_or_set_user(auth_token=token,
                           profile=profile,
                           auth_opts=auth_opts)
コード例 #7
0
ファイル: export.py プロジェクト: seniorivn/ExporterToLeo
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from word import Kindle, Text, Input, Subs
from config import sources, auth
from service import Lingualeo
import sys
import traceback

email = auth.get('email')
password = auth.get('password')

try:
    export_type = sys.argv[1]
    if export_type == 'text':
        if len(sys.argv) == 3:
            source = sys.argv[2]
        else:
            source = sources.get('text')
        handler = Text(source)
    elif export_type == 'kindle':
        handler = Kindle(sources.get('kindle'))
    elif export_type == 'input':
        handler = Input(sys.argv[2:])
    elif export_type == 'subs':
        handler = Subs(sys.argv[2:])
    else:
        raise Exception('unsupported type')

    handler.read()

    lingualeo = Lingualeo(email, password)