示例#1
0
    def test_get_auth_url_single_select_junk_keys(self):
        info = {"pizza": "TESLA"}

        client = smartcar.AuthClient(
            self.client_id,
            self.client_secret,
            self.redirect_uri,
            self.scope,
            development=False,
        )

        actual = client.get_auth_url(force=True,
                                     state="stuff",
                                     single_select="potato")

        actual_query = urlparse(actual).query
        expected_query = urlencode({
            "response_type": "code",
            "client_id": self.client_id,
            "redirect_uri": self.redirect_uri,
            "approval_prompt": "force",
            "state": "stuff",
            "scope": " ".join(self.scope),
            "single_select": False,
        })

        expected_params = parse_qs(expected_query)
        actual_params = parse_qs(actual_query)

        assertDeepEquals(self, expected_params, actual_params)
示例#2
0
    def test_get_auth_url_vehicle_info_dictionary(self):
        info = {"make": "TESLA"}

        client = smartcar.AuthClient(
            self.client_id,
            self.client_secret,
            self.redirect_uri,
            self.scope,
            development=False,
        )

        actual = client.get_auth_url(force=True,
                                     state="stuff",
                                     vehicle_info=info)

        actual_query = urlparse(actual).query
        expected_query = urlencode({
            "response_type": "code",
            "client_id": self.client_id,
            "redirect_uri": self.redirect_uri,
            "approval_prompt": "force",
            "state": "stuff",
            "scope": " ".join(self.scope),
            "make": "TESLA",
        })

        expected_params = parse_qs(expected_query)
        actual_params = parse_qs(actual_query)

        assertDeepEquals(self, expected_params, actual_params)
示例#3
0
    def test_get_auth_url_single_select_dictionary_vin(self):
        single_select = {"vin": "12345678901234"}

        client = smartcar.AuthClient(
            self.client_id,
            self.client_secret,
            self.redirect_uri,
            self.scope,
            development=False,
        )

        actual = client.get_auth_url(force=True,
                                     state="stuff",
                                     single_select=single_select)

        query = urlencode({
            "response_type": "code",
            "client_id": self.client_id,
            "redirect_uri": self.redirect_uri,
            "approval_prompt": "force",
            "state": "stuff",
            "scope": " ".join(self.scope),
            "state": "stuff",
            "single_select_vin": "12345678901234",
            "single_select": True,
        })

        expected_params = parse_qs(query)
        actual_params = parse_qs(urlparse(actual).query)

        assertDeepEquals(self, expected_params, actual_params)
示例#4
0
    def __init__(self, credentials='credentials/key_SMARTCAR.json'):

        prm = ['read_odometer', 'read_location', 'read_battery']
        with open(credentials) as raw:
            crd = json.load(raw)
        self.clt = smartcar.AuthClient(crd['id'], crd['key'],
                                       'http://localhost:8080', prm)
    def test_get_auth_url_single_select_junk_keys(self):
        info = {
            'pizza': 'TESLA'
        }
        
        client = smartcar.AuthClient(self.client_id, self.client_secret,
                self.redirect_uri, self.scope, development=False)

        actual = client.get_auth_url(force=True, state='stuff', single_select='potato')

        query = urlencode({
            'response_type': 'code',
            'client_id': self.client_id,
            'redirect_uri': self.redirect_uri,
            'approval_prompt': 'force',
            'state': 'stuff',
            'scope': ' '.join(self.scope),
            'single_select': False
        })

        expected = smartcar.const.CONNECT_URL + '/oauth/authorize?' + query

        expected_params = parse_qs(expected)
        actual_params = parse_qs(actual)

        assertDeepEquals(self, expected_params, actual_params)
示例#6
0
 async def authenticate(self, data) -> bool:
     callback_url = f"{get_url(self.hass, prefer_external=True)}{AUTH_CALLBACK_PATH}"
     _LOGGER.exception(callback_url)
     callback_url = "https://ha.dumpin.in"
     scoper = [
         "read_odometer",
         "required:read_location",
         "read_vehicle_info",
         "read_engine_oil",
         "read_battery",
         "read_charge",
         "read_fuel",
         "control_security",
         "read_tires",
         "read_vin",
     ]
     _LOGGER.exception(callback_url)
     client = smartcar.AuthClient(
         client_id=data["client_id"],
         client_secret=data["client_secret"],
         redirect_uri=callback_url,
         scope=scoper,
         test_mode=bool(data["test_mode"]),
     )
     try:
         auth_url = client.get_auth_url()
         _LOGGER.exception(auth_url)
         hass = self.hass
         hass.http.register_view(SmartCarAuthCallbackView())
         webbrowser.open(auth_url)
         """Test if we can authenticate with the host."""
         return True
     except:
         return False
示例#7
0
    def test_get_auth_url_single_select_junk_values(self):
        client = smartcar.AuthClient(
            self.client_id,
            self.client_secret,
            self.redirect_uri,
            self.scope,
            development=False,
        )

        actual = client.get_auth_url(force=True,
                                     state="stuff",
                                     single_select="potato")

        query = urlencode({
            "response_type": "code",
            "client_id": self.client_id,
            "redirect_uri": self.redirect_uri,
            "approval_prompt": "force",
            "state": "stuff",
            "scope": " ".join(self.scope),
            "single_select": False,
        })

        expected = smartcar.const.CONNECT_URL + "/oauth/authorize?" + query

        expected_params = parse_qs(query)
        actual_params = parse_qs(query)

        assertDeepEquals(self, expected_params, actual_params)
    def test_get_auth_url_single_select_dictionary_vin(self):
        single_select = {
            'vin': '12345678901234'
        }

        client = smartcar.AuthClient(self.client_id, self.client_secret,
                self.redirect_uri, self.scope, development=False)

        actual = client.get_auth_url(force=True, state='stuff', single_select=single_select)

        query = urlencode({
            'response_type': 'code',
            'client_id': self.client_id,
            'redirect_uri': self.redirect_uri,
            'approval_prompt': 'force',
            'state': 'stuff',
            'scope': ' '.join(self.scope),
            'state': 'stuff',
            'single_select_vin': '12345678901234',
            'single_select': True
        })

        expected_params = parse_qs(query)
        actual_params = parse_qs(urlparse(actual).query)

        assertDeepEquals(self, expected_params, actual_params)
示例#9
0
    def setUpClass(cls):
        def get_code(driver, auth_url):
            driver.get(auth_url)

            chevy_button = WebDriverWait(driver, 10).until(
                EC.presence_of_element_located((
                    By.CSS_SELECTOR,
                    "button[data-make='CHEVROLET']")))
            chevy_button.click()

            username = uuid.uuid4()
            username = str(username) + '@mock.com'

            sign_in_button = WebDriverWait(driver, 10).until(
                EC.presence_of_element_located((By.ID, 'sign-in-button')))
            driver.find_element_by_id('username').send_keys(username)
            driver.find_element_by_id('password').send_keys('password')
            sign_in_button.click()

            permissions_approval_button = WebDriverWait(driver, 10).until(
                EC.presence_of_element_located((By.ID, 'approval-button')))
            permissions_approval_button.click()

            url = driver.current_url
            parsed_url = urlparse.urlparse(url)
            return urlparse.parse_qs(parsed_url.query)['code'][0]

        client_id = os.environ['INTEGRATION_CLIENT_ID']
        client_secret = os.environ['INTEGRATION_CLIENT_SECRET']
        redirect_uri = 'https://example.com/auth'
        scope = [
            'required:control_security:unlock',
            'required:control_security:lock',
            'required:read_vehicle_info',
            'required:read_vin',
            'required:read_location',
            'required:read_odometer',
            'required:read_fuel',
            'required:read_battery',
            'required:read_charge'
        ]
        test_mode = True

        cls.client = smartcar.AuthClient(
            client_id,
            client_secret,
            redirect_uri,
            scope,
            test_mode
        )

        cls.driver = webdriver.Remote(
            command_executor='http://127.0.0.1:4444/wd/hub',
            desired_capabilities=DesiredCapabilities.CHROME,
            keep_alive=True)

        auth_url = cls.client.get_auth_url()

        cls.code = get_code(cls.driver, auth_url)
示例#10
0
 def setUp(self):
     self.client_id = 'client-id'
     self.client_secret = 'client-secret'
     self.redirect_uri = 'https://redirect.uri'
     self.scope = ['a', 'b', 'c']
     self.client = smartcar.AuthClient(self.client_id, self.client_secret,
             self.redirect_uri, self.scope, True)
     self.maxDiff = None
     self.basic_auth = basic_auth(self.client_id, self.client_secret)
     self.expected = {'key': 'value', 'expires_in':7200}
示例#11
0
 def setUp(self):
     self.client_id = "client-id"
     self.client_secret = "client-secret"
     self.redirect_uri = "https://redirect.uri"
     self.scope = ["a", "b", "c"]
     self.client = smartcar.AuthClient(self.client_id, self.client_secret,
                                       self.redirect_uri, self.scope, True)
     self.maxDiff = None
     self.basic_auth = basic_auth(self.client_id, self.client_secret)
     self.expected = {"key": "value", "expires_in": 7200}
示例#12
0
    def test_is_compatible(self):
        client = smartcar.AuthClient(*get_auth_client_params())

        teslaVin = "5YJXCDE22HF068739"
        audiVin = "WAUAFAFL1GN014882"

        scopes = ["read_odometer", "read_location"]

        teslaComp = client.is_compatible(teslaVin, scopes)
        audiComp = client.is_compatible(audiVin, scopes)

        self.assertTrue(teslaComp)
        self.assertFalse(audiComp)
示例#13
0
    def test_get_auth_url(self):
        client = smartcar.AuthClient(self.client_id, self.client_secret,
                self.redirect_uri, self.scope)
        actual = client.get_auth_url(force=True, state='stuff')
        query = urlencode({
            'response_type': 'code',
            'client_id': self.client_id,
            'redirect_uri': self.redirect_uri,
            'approval_prompt': 'force',
            'scope': ' '.join(self.scope),
            'state': 'stuff'
        })
        expected = smartcar.const.CONNECT_URL + '/oauth/authorize?' + query

        expected_params = parse_qs(expected)
        actual_params = parse_qs(actual)

        assertDeepEquals(self, expected_params, actual_params)
示例#14
0
    def test_get_auth_url(self):
        client = smartcar.AuthClient(self.client_id, self.client_secret,
                                     self.redirect_uri, self.scope)
        actual = client.get_auth_url(force=True, state="stuff")
        query = urlencode({
            "response_type": "code",
            "client_id": self.client_id,
            "redirect_uri": self.redirect_uri,
            "approval_prompt": "force",
            "scope": " ".join(self.scope),
            "state": "stuff",
        })
        expected = smartcar.const.CONNECT_URL + "/oauth/authorize?" + query

        expected_params = parse_qs(expected)
        actual_params = parse_qs(actual)

        assertDeepEquals(self, expected_params, actual_params)
示例#15
0
    def test_exchange_code(self):
        client = smartcar.AuthClient(*get_auth_client_params())
        code = run_auth_flow(client.get_auth_url())

        def assert_access_object(access_object):
            self.assertIsNotNone(access_object)
            self.assertIn("access_token", access_object)
            self.assertIn("token_type", access_object)
            self.assertIn("refresh_token", access_object)
            self.assertIn("expires_in", access_object)
            self.assertIn("expiration", access_object)
            self.assertIn("refresh_expiration", access_object)

        access_object = client.exchange_code(code)
        assert_access_object(access_object)

        new_access_object = client.exchange_refresh_token(
            access_object["refresh_token"])
        assert_access_object(new_access_object)
示例#16
0
from flask import Flask, render_template, request, session, flash, redirect, jsonify
import json
import requests
from requests.auth import HTTPBasicAuth
import os
from flask_sqlalchemy import SQLAlchemy
import smartcar
import datetime
from model import User, Vehicle, UserVehicle, connect_to_db, db, Service

client = smartcar.AuthClient(
    client_id=os.environ["CLIENT_ID"],
    client_secret=os.environ["CLIENT_SECRET"],
    redirect_uri='http://*****:*****@app.route("/registration", methods=["GET"])
def render_registration_form():
    """render registration form"""

    return render_template("register.html")


@app.route("/registration", methods=["POST"])
示例#17
0
文件: test.py 项目: sakchoudhary/OOF2
import smartcar
import webbrowser

#smartcar.AuthClient(client_id, client_secret, redirect_uri, scope, test_mode)
client = smartcar.AuthClient("90844701-84f0-4845-bb9f-6c060ce22216", "c489c726-b7dc-4f77-bcdf-a4584ac9cdb9", "http://localhost:8000/callback", scope=None, test_mode=False)
client.get_auth_url(force=True)
webbrowser.open(client.get_auth_url())
示例#18
0
import smartcar
from flask import Flask, redirect, request, jsonify, render_template
from flask_cors import CORS

import os

app = Flask(__name__)
CORS(app)

# global variable to save our access_token
access = None

client = smartcar.AuthClient(
    client_id='7126d3ad-f1bf-4712-b484-2e450efa1d5f',
    client_secret='36f18730-00e6-4b36-ae24-adbb44b59fa8',
    redirect_uri='http://*****:*****@app.route('/login', methods=['GET'])
def login():
    auth_url = client.get_auth_url()
    return redirect(auth_url)


@app.route('/exchange', methods=['GET'])
def exchange():
    code = request.args.get('code')

    # access our global variable and store our access tokens
示例#19
0
from config import *

app = Flask(__name__, static_folder="client")
app.secret_key = "not secret"
CORS(app)

# data about each vehicle
data_readings = {}

# list of phone numbers of potential victims
victims = []

smartcar_client = smartcar.AuthClient(
    client_id=CLIENT_ID,
    client_secret=CLIENT_SECRET,
    redirect_uri=REDIRECT_URI,
    scope=["read_vehicle_info", "read_odometer", 'read_location'],
    test_mode=TEST_MODE,
)

twilio_client = Client(TWILIO_SID, TWILIO_AUTH_TOKEN)

mongo_client = MongoClient(MONGO_URI)
db = mongo_client.get_database()


def get_token(user_id):
    access = db.access.find_one({"uid": user_id})
    if access:
        print(f"{datetime.datetime.now()} {access.get('expires_on')}")
        if datetime.datetime.now() > access.get("expires_on"):
示例#20
0
from enum import Enum
from collections import namedtuple

import requests
import smartcar

CLIENT_ID = '52e8d23b-b296-4f8b-89a0-18b64fac4b38'
CLIENT_SECRET = '13a5b398-ebf1-433f-a82f-60a5224548d8'

client = smartcar.AuthClient(client_id=CLIENT_ID,
                             client_secret=CLIENT_SECRET,
                             redirect_uri='http://localhost:5000/callback',
                             scope=[
                                 'read_vehicle_info',
                                 'read_vin',
                                 'read_charge',
                                 'read_battery',
                                 'control_security',
                             ],
                             test_mode=True)


class ChargingState(Enum):
    FULLY_CHARGED = 1
    CHARGING = 2
    NOT_CHARGING = 3


ChargingStatus = namedtuple('ChargingStatus', ['state', 'is_plugged_in'])
BatteryStatus = namedtuple('BatteryStatus', ['range', 'percent_remaining'])
AccessTokens = namedtuple('AccessTokens', ['token', 'expiration', 'refresh'])
示例#21
0
app = Flask(__name__)
CORS(app)

app.secret_key = 'xb2@<4*axd3x7fxb9x9bxdcD&x88x01xe0xd2x9dxdcxcc4nxf3v'



access = None
range_left = None
percentRemaining = None


client = smartcar.AuthClient(
    client_id=os.environ.get("CLIENT_ID"),
    client_secret=os.environ.get("CLIENT_SECRET"),
    redirect_uri="http://*****:*****@app.route('/login', methods=['GET'])
def login():
   
    auth_url = client.get_auth_url()
    return redirect(auth_url)




@app.route('/exchange', methods=['GET'])
def exchange():
示例#22
0
CLIENT_ID = 'ae64785d-d7ab-4c00-a039-e4916cc9cec2'
CLIENT_SECRET = '878e402c-75a2-4396-8519-b61a80cfbad5'
REDIRECT_URI='http://*****:*****@app.route('/login', methods=['GET'])
def login():
    # TODO: Authorization Step 1b: Launch Smartcar authorization dialog
    auth_url = client.get_auth_url()
    return redirect(auth_url)

    pass


@app.route('/exchange', methods=['GET'])
示例#23
0
from flask import Flask, redirect, request, jsonify
from flask_cors import CORS

import os

app = Flask(__name__)
CORS(app)

# global variable to save our access_token
access = None

client = smartcar.AuthClient(client_id=CLIENT_ID,
                             client_secret=CLIENT_SECRET,
                             redirect_uri=REDIRECT_URI,
                             scope=[
                                 'read_vehicle_info', 'read_location',
                                 'control_security', 'control_security:unlock',
                                 'control_security:lock', 'read_odometer'
                             ],
                             test_mode=False)


@app.route('/login', methods=['GET'])
def login():
    auth_url = client.get_auth_url(True)
    print(auth_url)
    return redirect(auth_url)


@app.route('/exchange', methods=['GET'])
def exchange():
import smartcar
import secrets
from twilio.rest import Client
from flask import Flask, request, jsonify, session, render_template, redirect, flash


account_sid = secrets.ACCOUNT_SID
auth_token = secrets.AUTH_TOKEN
smsClient = Client(account_sid, auth_token)
redirect_uri = secrets.REDIRECT_URI

app = Flask(__name__)
app.secret_key = 'blah!'
client = smartcar.AuthClient(
    client_id=secrets.CLIENT_ID,
    client_secret=secrets.CLIENT_SECRET,
    redirect_uri=redirect_uri,
    scope=['read_vehicle_info', 'read_location', 'read_odometer', 'control_security', 'read_vin']
)


@app.route('/', methods=['GET'])
def index():
    auth_url = client.get_auth_url(force=True)
    return '''
        <h1>Hello, Hackbright!</h1>
        <a href=%s>
          <button>Connect Car</button>
        </a>
    ''' % auth_url

示例#25
0
import os
from flask import Flask, redirect, request, jsonify, render_template, url_for, session
from flask_cors import CORS
from moneyRequests import sendMoneyRequestOneTimeContact

app = Flask(__name__)
app.secret_key = os.urandom(16)
CORS(app)
# global variable to save our access_token
access = None

client = smartcar.AuthClient(
    client_id='8af861e3-570a-45f5-b321-ef755778ff42',
    client_secret='bacddc7a-d359-46de-a56d-d6f5c338edc5',
    redirect_uri='http://localhost:5000/smartcar/exchange',
    scope=[
        'read_vehicle_info', 'control_security', 'read_odometer',
        'read_location'
    ],
    test_mode=False)
login_manager = log.LoginManager()
login_manager.init_app(app)
""" LOGIN """


@login_manager.user_loader
def load_user(user_id):
    user = db.fetch_user_from_id(int(user_id))
    return User(user['id'], user['email'])

示例#26
0
import smartcar
from flask import Flask, request, jsonify
import json

with open("config.json", 'r') as f:
    config = json.load(f)

app = Flask(__name__)

client = smartcar.AuthClient(
    client_id=config['client_id'],
    client_secret=config['client_secret'],
    redirect_uri='http://*****:*****@app.route('/', methods=['GET'])
def index():
    auth_url = client.get_auth_url(force=True)
    return '''
        <h1>Hello, Hackbright!</h1>
        <a href=%s>
          <button>Connect Car</button>
        </a>
    ''' % auth_url


@app.route('/callback', methods=['GET'])
def callback():
    code = request.args.get('code')
示例#27
0
文件: main.py 项目: tkbeal/hackru2019
CORS(app)

#Firestore creds
cred = credentials.Certificate('../key.json')
firebase_admin.initialize_app(cred)

db = firestore.client()

# global variable to save our access_token
access = None

client = smartcar.AuthClient(
    client_id=os.environ.get('CLIENT_ID'),
    client_secret=os.environ.get('CLIENT_SECRET'),
    redirect_uri=os.environ.get('REDIRECT_URI'),
    scope=[
        'read_vehicle_info read_odometer read_location control_security control_security:lock read_vin'
    ],
    test_mode=True,
)


@app.route('/login', methods=['GET'])
def login():
    auth_url = client.get_auth_url()
    return redirect(auth_url)


@app.route('/exchange', methods=['GET'])
def exchange():
    user_id = request.args.get('user_id')
示例#28
0
from flask import Flask, redirect, request, jsonify
from flask_cors import CORS

app = Flask(__name__)
CORS(app)

# global variable to save our access_token
access = None

# dictionary that holds the vehicles in distance
vehicles = {}

client = smartcar.AuthClient(
    client_id='8eca448e-03f2-488f-98b1-31776e6c8662',
    client_secret='03206382-8351-429d-9f31-4ece3ce3c407',
    redirect_uri='http://*****:*****@app.route('/login', methods=['GET'])
def login():
    auth_url = client.get_auth_url()
    return redirect(auth_url)


@app.route('/exchange', methods=['GET'])
def exchange():
    code = request.args.get('code')
示例#29
0
# ./main.py
import smartcar
from flask import Flask, request, redirect, jsonify
from flask_cors import CORS

app = Flask(__name__)
CORS(app)

# global variable to save our access_token
access = None

client = smartcar.AuthClient(
    client_id='906e6fc9-ee9e-4622-b19c-6055e4a7afe0',
    client_secret='nope',
    redirect_uri='http://*****:*****@app.route('/login', methods=['GET'])
def login():
    auth_url = client.get_auth_url()
    return redirect(auth_url)


@app.route('/exchange', methods=['GET'])
def exchange():
    code = request.args.get('code')
示例#30
0
import MapInterface
import smartcar
import os
from flask import Flask, jsonify, request, redirect

app = Flask(__name__)

# global variable to save our access_token
access = None
fOdometer = None
lOdometer = None

client = smartcar.AuthClient(
    client_id='1714bcc1-e189-489f-81f1-aaf39fe89785',
    client_secret='4d17ecec-e19a-4616-baf3-ca83ad334eae',
    redirect_uri='http://*****:*****@app.route("/")
def hello():
    return "this is the home route"


'''
return sample data set of all local landmarks for user to choose