cabana: merge in google auth

main
Andy Haden 2017-08-15 17:12:27 -07:00
parent 295300703a
commit f741df65f5
3 changed files with 19 additions and 9 deletions

View File

@ -1,9 +1,19 @@
import Cookies from 'js-cookie';
import {COMMA_ACCESS_TOKEN_COOKIE, COMMA_OAUTH_REDIRECT_COOKIE} from '../config';
function getCommaAccessToken() {
return Cookies.get(COMMA_ACCESS_TOKEN_COOKIE);
}
function isAuthenticated() {
return Math.random() < 0.5;
return getCommaAccessToken() !== undefined;
}
function authUrl() {
return window.location.href;
Cookies.set(COMMA_OAUTH_REDIRECT_COOKIE, window.location.href);
return 'https://community.comma.ai/ucp.php?mode=login&login=external&oauth_service=google';
}
export default {isAuthenticated, authUrl};
export default {getCommaAccessToken, isAuthenticated, authUrl};

View File

@ -1,5 +1,6 @@
import Cookies from 'js-cookie';
import Moment from 'moment';
import CommaAuth from './comma-auth';
const ROUTES_ENDPOINT = 'https://api.commadotai.com/v1/{dongleId}/routes/';
@ -75,10 +76,6 @@ let DEMO_ROUTES = {
DEMO_ROUTES = momentizeTimes(DEMO_ROUTES);
function getCommaAccessToken() {
return Cookies.get('comma_access_token');
}
function momentizeTimes(routes) {
for(let routeName in routes) {
routes[routeName].start_time = Moment(routes[routeName].start_time);
@ -92,11 +89,11 @@ export async function fetchRoutes(dongleId) {
dongleId = 'me';
}
const accessToken = getCommaAccessToken();
const accessToken = CommaAuth.getCommaAccessToken();
if(accessToken) {
const endpoint = ROUTES_ENDPOINT.replace('{dongleId}', dongleId);
const headers = new Headers();
headers.append('Authorization', `JWT ${getCommaAccessToken()}`);
headers.append('Authorization', `JWT ${accessToken}`);
try {
const request = new Request(endpoint, {headers});

View File

@ -23,3 +23,6 @@ export const PART_SEGMENT_LENGTH = 3;
export const CAN_GRAPH_MAX_POINTS = 10000;
export const STREAMING_WINDOW = 60;
export const COMMA_ACCESS_TOKEN_COOKIE = 'comma_access_token';
export const COMMA_OAUTH_REDIRECT_COOKIE = 'wiki_login_redirect';