From 70a791396f4f88c058299e4f3a6974be52ef83db Mon Sep 17 00:00:00 2001 From: Youngchan Je Date: Wed, 28 Dec 2016 14:10:23 +0900 Subject: [PATCH 1/3] allowing to exclude secret on demand --- firebase.coffee | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/firebase.coffee b/firebase.coffee index 375e793..8006704 100644 --- a/firebase.coffee +++ b/firebase.coffee @@ -26,8 +26,9 @@ class exports.Firebase extends Framer.BaseClass @secret = @options.secret ?= null @debug = @options.debug ?= false @_status ?= "disconnected" - super + @secretEndPoint = if @secret then "?auth=#{@secret}" else "" + super console.log "Firebase: Connecting to Firebase Project '#{@projectID}' ... \n URL: 'https://#{@projectID}.firebaseio.com'" if @debug @.onChange "connection" @@ -35,7 +36,7 @@ class exports.Firebase extends Framer.BaseClass request = (project, secret, path, callback, method, data, parameters, debug) -> - url = "https://#{project}.firebaseio.com#{path}.json?auth=#{secret}" + url = "https://#{project}.firebaseio.com#{path}.json#{secret}" unless parameters is undefined @@ -87,11 +88,11 @@ class exports.Firebase extends Framer.BaseClass # Available methods - get: (path, callback, parameters) -> request(@projectID, @secret, path, callback, "GET", null, parameters, @debug) - put: (path, data, callback, parameters) -> request(@projectID, @secret, path, callback, "PUT", data, parameters, @debug) - post: (path, data, callback, parameters) -> request(@projectID, @secret, path, callback, "POST", data, parameters, @debug) - patch: (path, data, callback, parameters) -> request(@projectID, @secret, path, callback, "PATCH", data, parameters, @debug) - delete: (path, callback, parameters) -> request(@projectID, @secret, path, callback, "DELETE", null, parameters, @debug) + get: (path, callback, parameters) -> request(@projectID, @secretEndPoint, path, callback, "GET", null, parameters, @debug) + put: (path, data, callback, parameters) -> request(@projectID, @secretEndPoint, path, callback, "PUT", data, parameters, @debug) + post: (path, data, callback, parameters) -> request(@projectID, @secretEndPoint, path, callback, "POST", data, parameters, @debug) + patch: (path, data, callback, parameters) -> request(@projectID, @secretEndPoint, path, callback, "PATCH", data, parameters, @debug) + delete: (path, callback, parameters) -> request(@projectID, @secretEndPoint, path, callback, "DELETE", null, parameters, @debug) @@ -100,7 +101,7 @@ class exports.Firebase extends Framer.BaseClass if path is "connection" - url = "https://#{@projectID}.firebaseio.com/.json?auth=#{@secret}" + url = "https://#{@projectID}.firebaseio.com/.json#{@secretEndPoint}" currentStatus = "disconnected" source = new EventSource(url) @@ -121,7 +122,7 @@ class exports.Firebase extends Framer.BaseClass else - url = "https://#{@projectID}.firebaseio.com#{path}.json?auth=#{@secret}" + url = "https://#{@projectID}.firebaseio.com#{path}.json#{@secretEndPoint}" source = new EventSource(url) console.log "Firebase: Listening to changes made to '#{path}' \n URL: '#{url}'" if @debug From 1350b172ae9cd6dadb5dea0f846c9d52196400b8 Mon Sep 17 00:00:00 2001 From: Youngchan Je Date: Wed, 28 Dec 2016 15:30:30 +0900 Subject: [PATCH 2/3] added description on how to exclude secret --- README.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c9e9888..b1cdf10 100755 --- a/README.md +++ b/README.md @@ -75,7 +75,8 @@ This module is based on [Firebase's REST API](https://firebase.google.com/docs/r | :--- | | [**1) Properties**](https://github.com/marckrenn/framer-Firebase#1-properties) | | \|--- [firebase**.projectID**, **.secret**](https://github.com/marckrenn/framer-Firebase#-firebaseprojectid-firebasesecret) | -| \|--- [firebase**.debug**](https://github.com/marckrenn/framer-Firebase#-firebasedebug) | +| \|--- [firebase**.secret**](https://github.com/marckrenn/framer-Firebase#-firebasesecret) | +| \|--- [firebase**.debug**](https://github.com/marckrenn/framer-Firebase#-firebasedebug) | | \|--- [firebase**.status**](https://github.com/marckrenn/framer-Firebase#-firebasestatus-read-only) | | [**2) Methods**](https://github.com/marckrenn/framer-Firebase#2-methods) | | \|--- [firebase**.get**()](https://github.com/marckrenn/framer-Firebase#-firebasegetpath-callback-parameters) | @@ -113,6 +114,23 @@ firebase = new Firebase
+#### • firebase.secret +If you wish not to share your *secret*, please follow the next steps. + +1. Simply, do not use *secret* on your code. (remove it if you have already) +2. Go to *Console* → *YourProject* → *Database* → *RULES* +3. Change the rules of `.read` and `.write` to `true` like the following: +```json +{ + "rules": { + ".read": "true", + ".write": "true" + } +} +``` + +
+ #### • firebase.debug --- If set to **true**, relevant connection messages will be logged to the console. From 95c955475d235cb74889f36e6b7820b011798078 Mon Sep 17 00:00:00 2001 From: Youngchan Je Date: Wed, 28 Dec 2016 15:34:02 +0900 Subject: [PATCH 3/3] following README styles --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b1cdf10..d291c33 100755 --- a/README.md +++ b/README.md @@ -115,6 +115,7 @@ firebase = new Firebase
#### • firebase.secret +--- If you wish not to share your *secret*, please follow the next steps. 1. Simply, do not use *secret* on your code. (remove it if you have already)