From f3aeb4627b11024f3f13d89a0a784400dd445eb7 Mon Sep 17 00:00:00 2001 From: sahabaishakhi Date: Tue, 12 May 2020 17:01:33 +0530 Subject: [PATCH] CORS error for google API GET request with access token --- project.clj | 6 ++---- src/clj/googlefit_api_test/core.clj | 17 ++--------------- src/cljs/googlefit-api-test/core.cljs | 10 ++++++++++ 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/project.clj b/project.clj index 214ae53..a3a7d0b 100644 --- a/project.clj +++ b/project.clj @@ -4,11 +4,9 @@ :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0" :url "https://www.eclipse.org/legal/epl-2.0/"} :dependencies [[org.clojure/clojure "1.10.0"] - [ring/ring-jetty-adapter "1.8.0"] - [compojure "1.6.1"] [org.clojure/clojurescript "1.10.312"] - [reagent "0.9.1"] - [ring-server "0.5.0"]] + [ring "1.7.1"] + [reagent "0.9.1"]] :repl-options {:init-ns googlefit-api-test.core} :main googlefit-api-test.core :source-paths ["src/clj" "src/cljs"] diff --git a/src/clj/googlefit_api_test/core.clj b/src/clj/googlefit_api_test/core.clj index 918eeef..d2f0909 100644 --- a/src/clj/googlefit_api_test/core.clj +++ b/src/clj/googlefit_api_test/core.clj @@ -1,18 +1,5 @@ (ns googlefit-api-test.core - (:require [compojure.core :refer [defroutes ANY POST GET]] - [compojure.route :refer [not-found resources]] - [ring.adapter.jetty :as jetty] - [ring.util.response :as resp] - [ring.middleware.reload :refer [wrap-reload]])) - -;; (defroutes app-routes -;; (GET "/" [] (resp/resource-response "index.html" {:root "public"})) -;; (resources "/") -;; (not-found "

Page not found

")) - -;; (defn -main [] -;; (jetty/run-jetty (wrap-reload #'app-routes) {:port 8000}) -;; (println (str "Server is running on port 8000"))) + (:require [ring.util.response :as resp])) (def route-set #{"/" "/tokenpage"}) @@ -21,4 +8,4 @@ (when (route-set (:uri req)) (some-> (resp/resource-response "index.html" {:root "public"}) (resp/content-type "text/html; charset=utf-8"))) - (not-found "Not found"))) + (resp/not-found "Not found"))) diff --git a/src/cljs/googlefit-api-test/core.cljs b/src/cljs/googlefit-api-test/core.cljs index 8f2eaf8..c55a053 100644 --- a/src/cljs/googlefit-api-test/core.cljs +++ b/src/cljs/googlefit-api-test/core.cljs @@ -10,6 +10,16 @@ (println fragment-string) +(def xhr (js/XMLHttpRequest.)) + +(.open xhr "GET" (str "https://www.googleapis.com/fitness/v1/users/me/dataSources" "access_token=" fragment-string) true) + +(. xhr send) + +(println (.-status xhr)) + +;; (set! (. xhr onreadystatechange) (fn [] (js/console.log (.response xhr)))) + (defn appended-container [target] (let [oauth2-end-point "https://accounts.google.com/o/oauth2/v2/auth?scope=https%3A//www.googleapis.com/auth/fitness.activity.read&include_granted_scopes=true&response_type=token&redirect_uri=http%3A//localhost%3A9500/tokenpage&client_id=857819587666-2pm3q0sv9lvmv697afm0k6jblgvtjon9.apps.googleusercontent.com"