コード例 #1
0
ファイル: app.py プロジェクト: brucx/uberpku
def oauth():
    auth_flow = AuthorizationCodeGrant(
    credentials.get('client_id'),
    credentials.get('scopes'),
    credentials.get('client_secret'),
    credentials.get('redirect_url'),
    )
    session = auth_flow.get_session(request.url)
    oauth2credential = session.oauth2credential
    token = {
        "client_id":oauth2credential.client_id,
        "access_token":oauth2credential.access_token,
        "expires_in_seconds": oauth2credential.expires_in_seconds,
        "scopes": list(oauth2credential.scopes),
        "grant_type": oauth2credential.grant_type,
        "redirect_url": oauth2credential.redirect_url,
        "client_secret": oauth2credential.client_secret,
        "refresh_token": oauth2credential.refresh_token,
    }
    client = UberRidesClient(session)
    response = client.get_user_profile()
    profile = response.json
    uuid = profile.get('uuid')
    api.set_token(uuid,token)
    return render_template('oauth2.html', uuid=uuid, token=token)
コード例 #2
0
def authorization_code_grant_flow(credentials, storage_filename):
    """Get an access token through Authorization Code Grant.

    Parameters
        credentials (dict)
            All your app credentials and information
            imported from the configuration file.
        storage_filename (str)
            Filename to store OAuth 2.0 Credentials.

    Returns
        (UberRidesClient)
            An UberRidesClient with OAuth 2.0 Credentials.
    """
    auth_flow = AuthorizationCodeGrant(
        credentials.get('client_id'),
        credentials.get('scopes'),
        credentials.get('client_secret'),
        credentials.get('redirect_url'),
    )

    auth_url = auth_flow.get_authorization_url()
    login_message = 'Login and grant access by going to:\n{}\n'
    login_message = login_message.format(auth_url)
    response_print(login_message)

    redirect_url = 'Copy the URL you are redirected to and paste here: \n'
    result = raw_input(redirect_url).strip()

    try:
        session = auth_flow.get_session(result)

    except (ClientError, UberIllegalState), error:
        fail_print(error)
        return
コード例 #3
0
    def uber_profile_exists(self):
        ### ----- Check if user has Uber Profile -----------#

        contents = self.content
        client_id = contents['client_id']
        scopes = set(contents['scopes'])
        client_secret = contents['client_secret']
        redirect_uri = contents['redirect_uri']
        code = contents['code']

        auth_flow = AuthorizationCodeGrant(client_id, scopes, client_secret,
                                           redirect_uri)
        auth_url = auth_flow.get_authorization_url()
        r = requests.get(auth_url, allow_redirects=True)
        encodedStr = r.url
        # Get rid of Url encoding
        decoded_url = unquote(encodedStr)
        idx = decoded_url.index("state=")
        state_str = decoded_url[idx:]

        # TODO: FIGURE OUT Whats going on with redirect URI
        new_redirect_url = redirect_uri + "?" + code + "&" + state_str

        # TODO: Figure this out for new session
        session = auth_flow.get_session(new_redirect_url)
        client = UberRidesClient(session, sandbox_mode=True)
        credentials = session.oauth2credential
        response = client.get_user_profile()
        profile = response.json
        email = profile.get('email')
        #THIS Is all a guess:
        has_uber_profile = True if email is not None else False
        return has_uber_profile
コード例 #4
0
ファイル: uberUtils.py プロジェクト: nirmitdesai/smartmirror
def authorization_code_grant_flow(credentials, storage_filename):
    """Get an access token through Authorization Code Grant.

    Parameters
        credentials (dict)
            All your app credentials and information
            imported from the configuration file.
        storage_filename (str)
            Filename to store OAuth 2.0 Credentials.

    Returns
        (UberRidesClient)
            An UberRidesClient with OAuth 2.0 Credentials.
    """
    print credentials.get('scopes')
    auth_flow = AuthorizationCodeGrant(
        credentials.get('client_id'),
        credentials.get('scopes'),
        credentials.get('client_secret'),
        credentials.get('redirect_url'),
    )

    auth_url = auth_flow.get_authorization_url()
    login_message = 'Login and grant access by going to:\n{}\n'
    login_message = login_message.format(auth_url)
    print(login_message)

    redirect_url = 'Copy the URL you are redirected to and paste here: \n'
    result = input(redirect_url).strip()

    try:
        session = auth_flow.get_session(result)

    except (ClientError, UberIllegalState) as error:
        print "failed........"
        print(error)
        return

    credential = session.oauth2credential

    credential_data = {
        'client_id': credential.client_id,
        'redirect_url': credential.redirect_url,
        'access_token': credential.access_token,
        'expires_in_seconds': credential.expires_in_seconds,
        'scopes': list(credential.scopes),
        'grant_type': credential.grant_type,
        'client_secret': credential.client_secret,
        'refresh_token': credential.refresh_token,
    }

    with open(storage_filename, 'w') as fp:
        print "dumped to file!"
        json.dump(credential_data,fp)

    return UberRidesClient(session, sandbox_mode=True)
コード例 #5
0
def authorization_code_grant_flow(credentials, storage_filename):
    """Get an access token through Authorization Code Grant.

    Parameters
        credentials (dict)
            All your app credentials and information
            imported from the configuration file.
        storage_filename (str)
            Filename to store OAuth 2.0 Credentials.

    Returns
        (UberRidesClient)
            An UberRidesClient with OAuth 2.0 Credentials.
    """
    auth_flow = AuthorizationCodeGrant(
        credentials.get('client_id'),
        credentials.get('scopes'),
        credentials.get('client_secret'),
        credentials.get('redirect_url'),
    )

    auth_url = auth_flow.get_authorization_url()
    login_message = 'Login and grant access by going to:\n{}\n'
    login_message = login_message.format(auth_url)
    response_print(login_message)

    redirect_url = 'Copy the URL you are redirected to and paste here: \n'
    result = input(redirect_url).strip()

    try:
        session = auth_flow.get_session(result)

    except (ClientError, UberIllegalState) as error:
        fail_print(error)
        return

    credential = session.oauth2credential

    credential_data = {
        'client_id': credential.client_id,
        'redirect_url': credential.redirect_url,
        'access_token': credential.access_token,
        'expires_in_seconds': credential.expires_in_seconds,
        'scopes': list(credential.scopes),
        'grant_type': credential.grant_type,
        'client_secret': credential.client_secret,
        'refresh_token': credential.refresh_token,
    }

    with open(storage_filename, 'w') as yaml_file:
        yaml_file.write(safe_dump(credential_data, default_flow_style=False))

    return UberRidesClient(session, sandbox_mode=True)
コード例 #6
0
def get_uber_products(start_latitude, start_longitude, redirect_url):
    auth_flow = AuthorizationCodeGrant(
        CLIENT_ID,
        PERMISSION_SCOPE,
        CLIENT_SECRET,
        REDIRECT_URI)
    auth_url = auth_flow.get_authorization_url()

    session = auth_flow.get_session(redirect_url)
    client = UberRidesClient(session)
    credentials = session.oauth2credential

    response = client.get_products(37.77, -122.41)
    products = response.json.get('products')
    print products
コード例 #7
0
def get_uber_rides_client(credential_storage_file_name):
    credentials = import_app_credentials('config.rider.yaml')

    auth_flow = AuthorizationCodeGrant(
        credentials.get('client_id'),
        credentials.get('scopes'),
        credentials.get('client_secret'),
        credentials.get('redirect_url'),
    )

    auth_url = auth_flow.get_authorization_url()
    login_message = 'Login as a rider and grant access by going to:\n\n{}\n'
    login_message = login_message.format(auth_url)
    print(login_message)

    redirect_url = 'Copy the URL you are redirected to and paste here: \n\n'
    result = input(redirect_url).strip()

    try:
        session = auth_flow.get_session(result)

    except (ClientError, UberIllegalState) as error:
        print("Error getting authorization session.")
        raise SystemExit(error)

    credential = session.oauth2credential

    credential_data = {
        'client_id': credential.client_id,
        'redirect_url': credential.redirect_url,
        'access_token': credential.access_token,
        'expires_in_seconds': credential.expires_in_seconds,
        'scopes': list(credential.scopes),
        'grant_type': credential.grant_type,
        'client_secret': credential.client_secret,
        'refresh_token': credential.refresh_token,
    }

    with open(credential_storage_file_name, 'w') as yaml_file:
        yaml_file.write(safe_dump(credential_data, default_flow_style=False))

    return UberRidesClient(session, sandbox_mode=True)
コード例 #8
0
def call_uber(flight_number, flight_origin_date):
    coords = get_coords(flight_number, flight_origin_date)
    server_token = "GSYPRMkSl_a7qQn8FH6d4imBjBnvrTWhh-6OzVPX"
    session = Session(server_token)
    client = UberRidesClient(session)
    response = client.get_products(coords[0], coords[1])
    products = response.json.get('products')
    auth_flow = AuthorizationCodeGrant(
        "gT2GLeVlXMQkrWWBO872bcjHK168Tr8W",
        None,
        "fQMuhWzwuvMiy2yl31qDu4xIRMP0DIVQQUtJy3hj",
        None,
    )
    auth_url = auth_flow.get_authorization_url()
    session = auth_flow.get_session()
    client = UberRidesClient(session, sandbox_mode=True)
    credentials = session.oauth2credential
    get_coords()
    response = client.request_ride(
        start_latitude=coords[0],
        start_longitude=coords[1],
    )
    ride_details = response.json
    ride_id = ride_details.get('request_id')
コード例 #9
0
import json
import requests
from uber_rides.auth import AuthorizationCodeGrant
from uber_rides.session import Session
from uber_rides.client import UberRidesClient

client_id = 'V4XWn0beV4JnKHHANILZdPXSMwPgh5-Y'
scopes = 'partner.accounts'
client_secret = 'v0RvnHN-EmCD0uG_1ybPwaFGQ2_VP9Z7UORf-oTn'
redirect_url = 'http://localhost:7000/submit'

auth_flow = AuthorizationCodeGrant(client_id, scopes, client_secret, redirect_url)
api_url = auth_flow.get_authorization_url()

print('Please go to %s and authorize access.' % api_url)
authorization_response = input('Enter the full callback URL: ')

session = auth_flow.get_session(authorization_response)
client = UberRidesClient(session, sandbox_mode=True)
credentials = session.oauth2credential

response = client.get_driver_trips()
trips = response.json

print(history)
コード例 #10
0
ファイル: uber.py プロジェクト: harshkothari410/uChat
#Destination : 40.502744, -74.448545
auth_url = auth_flow.get_authorization_url()

st = auth_url.find('state=')

ns = auth_url[st + len('state='):]
state = ns[:ns.find('&')]
print auth_url
print state

# redirect_uri = YOUR_REDIRECT_URL + '?code=' + access_token  + '&state=' + state
# print redirect_uri
# http://localhost/?state=o0tbQ7VtRzzBYtn0OALmjQY3XATB9UaU&code=fKW6qXnhmL1Naz6NvQ5TRwFkbZinNQ#_

redirect_uri = 'http://localhost/?state=' + state + '&code=t0Kq2Sfa55PifYK4L4cFiPTtfoBfrl#_'
session = auth_flow.get_session(redirect_uri)
client = UberRidesClient(session)
credentials = session.oauth2credential

print credentials

# session = Session(server_token=YOUR_SERVER_TOKEN)
# client = UberRidesClient(session)
response = client.get_products(40.488101, -74.437934)
products = response.json.get('products')

product_id = products[0].get('product_id')
print products[0].get('display_name')
estimate = client.estimate_ride(product_id=product_id,
                                start_latitude=40.488101,
                                start_longitude=-74.437934,