Skip to content

Commit 0e436b1

Browse files
committed
Fixes.
1 parent 09467de commit 0e436b1

File tree

8 files changed

+65
-50
lines changed

8 files changed

+65
-50
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This service allows you to securely authenticate users into your app. It uses Go
1313

1414
* Leverages the use of OAuth, saving time and effort.
1515
* Authenticate with `Facebook`, `Google`, `Twitter`, `Email`, `Anonymous` and more.
16-
* Generates an `idToken` that can be used for secure operations against Firebase Storage and Firebase Database.
16+
* Generates an `authToken` that can be used for secure operations against Firebase Storage and Firebase Database.
1717

1818
## Firebase Database
1919
*Main guide: [Firebase Database](./database)*
@@ -70,7 +70,7 @@ Free and open source!
7070

7171
These guides are based on the JavaScript SDK and therefore have their same limitation of being web based only. If you need the rest of features that Firebase offers I strongly recommend using an ANE.
7272

73-
### **Where did you got the documentation for Auth and Storage?**
73+
### **How did you got the documentation for Auth and Storage?**
7474

7575
I studied the JavaScript SDK and its official documentation, then I determined the API paths, requests, results and errors.
7676

auth/README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,21 +192,19 @@ This information is formatted the same for all providers, the most important val
192192
Name | Description
193193
---|---
194194
`localId`| A unique id assigned for the logged in user for your specific Firebase project. This is very useful when working with Firebase Database and Firebase Storage.
195-
`idToken`| An Authentication token that is used to identify the current logged in user. The `idToken` is heavily used in all Firebase features.
195+
`idToken`| An identity token that is used to identify the current logged in user. The `idToken` is used in further Auth requests such as exchanging it for an `access_token`.
196196
`displayName`| The logged in user full name (Google and Facebook) or their handler in Twitter.
197197
`photoUrl`| The logged in user avatar.
198198
`email`| The logged in user email address.
199199

200200
Note that not all providers return the same information, for example Twitter doesn't return an Email Address.
201201

202-
Once you have the profile information you might want to save it on an Object that can be globally accessed, you will need it when performing Auth requests against Firebase Database and Firebase Storage.
202+
Once you have the profile information you might want to save it on an Object that can be globally accessed, you might want to also save it to disk using a `SharedObject` or using the `FileStream` class.
203203

204-
The `idToken` you receive from this response doesn't work with Firebase Database and Firebase Storage requests. You must exchange it for a new one using the next method. It still works for further Firebase Auth requests.
204+
## Obtaining and Refreshing an Access Token
205205

206-
## Refreshing the idToken
207-
208-
By default the `idToken` has an expiration time of 60 minutes, you can reset its expiration by requesting a fresh one.
209-
To refresh an `idToken` you will only need to provide the previous one and specify the `grant_type` as `"authorization_code"`.
206+
By default the `access_token` has an expiration time of 60 minutes, you can reset its expiration by requesting a fresh one.
207+
To obtain or refresh an `access_token` you only need to provide the `idToken` from a Sign In or Verify Account request and specify the `grant_type` as `"authorization_code"`.
210208

211209
```actionscript
212210
private function refreshToken(idToken:String):void
@@ -231,7 +229,7 @@ private function refreshToken(idToken:String):void
231229
private function refreshTokenLoaded(event:flash.events.Event):void
232230
{
233231
var rawData:Object = JSON.parse(event.currentTarget.data);
234-
var newIdToken:String = rawData.access_token;
232+
var accessToken:String = rawData.access_token;
235233
}
236234
237235
private function errorHandler(event:flash.events.IOErrorEvent):void
@@ -256,3 +254,4 @@ A successful response will look like the following JSON structure:
256254

257255
Once you have got the `access_token` you are ready to perform secure operations against the Firebase Database and Firebase Storage services.
258256

257+
In this guide and examples, the `access_token` and `authToken` represent the same value.

auth/email/README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ The user will be automatically registered in the Auth section from your Firebase
7878

7979
For an Anonymous approach you don't need to specify anything in the request body. You will still get a response similar to the above just without an Email Address.
8080

81-
The `idToken` received from this response does work for the Firebase Database, Firebase Storage and Firebase Auth requests.
81+
The `idToken` received from this response can be used as an `authToken` for the Firebase Database, Firebase Storage and Firebase Auth requests.
82+
83+
Once this Sign Up token has expired you must refresh it (see bottom of this page).
8284

8385
## Verifying Credentials (Sign In)
8486

@@ -125,8 +127,7 @@ A successful response will look like the following JSON structure:
125127

126128
Note that failing to enter the correct password 3 times in a row will block the IP for future login attempts for a while.
127129

128-
The `idToken` received from this response doesn't work for Firebase Databasae and Firebase Storage requests. You must refresh the `idToken` to get a functional one (see bottom of this guide).
129-
It does still work for Firebase Auth requests.
130+
The `idToken` received from this response is used to perform further account management requests. It is also used to get an `access_token` for Auth requests. For more information see the bottom of this page.
130131

131132
## Password Reset
132133

@@ -387,10 +388,10 @@ A successful response will look like the following JSON structure:
387388
}
388389
```
389390

390-
## Refreshing the idToken
391+
## Obtaining and Refreshing an Access Token
391392

392-
By default the `idToken` has an expiration time of 60 minutes, you can reset its expiration by requesting a fresh one.
393-
To refresh an `idToken` you will only need to provide the previous one and specify the `grant_type` as `"authorization_code"`.
393+
By default the `access_token` has an expiration time of 60 minutes, you can reset its expiration by requesting a fresh one.
394+
To obtain or refresh an `access_token` you only need to provide the `idToken` from a Sign In or Verify Account request and specify the `grant_type` as `"authorization_code"`.
394395

395396
```actionscript
396397
private function refreshToken(idToken:String):void
@@ -415,7 +416,7 @@ private function refreshToken(idToken:String):void
415416
private function refreshTokenLoaded(event:flash.events.Event):void
416417
{
417418
var rawData:Object = JSON.parse(event.currentTarget.data);
418-
var newIdToken:String = rawData.access_token;
419+
var accessToken:String = rawData.access_token;
419420
}
420421
421422
private function errorHandler(event:flash.events.IOErrorEvent):void
@@ -438,4 +439,6 @@ A successful response will look like the following JSON structure:
438439
}
439440
```
440441

441-
Once you have got the `access_token` you are ready to perform secure operations against the Firebase Database and Firebase Storage services.
442+
Once you have got the `access_token` you are ready to perform secure operations against the Firebase Database and Firebase Storage services.
443+
444+
In this guide and examples, the `access_token` and `authToken` represent the same value.

database/README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ The `auth.uid` parameter means the following:
108108

109109
An Authentication Token is an encoded string that contains information about the user that is trying to perform an operation against the database.
110110

111-
There are several ways to generate these tokens, this guide will only explain how to do it using Google Identity Toolkit so you won't require to do Crytographic wizardy.
111+
There are several ways to generate these tokens, this guide will only explain how to do it using Google Identity Toolkit so you won't require to do Cryptographic wizardy.
112112

113-
For more detailed information on how to generate and manage an `idToken` please consult the [auth guide](/../auth).
113+
For more detailed information on how to generate and manage an `authToken` please consult the [Firebase Auth guide](/../auth).
114114

115-
Once you have got a fresh `idToken` you are ready to perform secure operations against the Firebase Database and Firebase Storage.
115+
Once you have got a fresh `authToken` you are ready to perform secure operations against the Firebase Database and Firebase Storage.
116116

117117
## Reading the Database
118118

@@ -142,9 +142,9 @@ A simple GET request (the default for `URLRequest`) is enough. Remember to alway
142142
To load a Private resource use the following code:
143143

144144
```actionscript
145-
private function loadSpecialOffers(idToken:String):void
145+
private function loadSpecialOffers(authToken:String):void
146146
{
147-
var request:URLRequest = new URLRequest("https://<YOUR-PROJECT-ID>.firebaseio.com/specialoffers.json?auth="+idToken);
147+
var request:URLRequest = new URLRequest("https://<YOUR-PROJECT-ID>.firebaseio.com/specialoffers.json?auth="+authToken);
148148
149149
var loader:URLLoader = new URLLoader();
150150
loader.addEventListener(flash.events.Event.COMPLETE, offersLoaded);
@@ -192,7 +192,7 @@ We used a `ProgressEvent.PROGRESS` instead of the usual `Event.COMPLETE`. Everyt
192192

193193
Remember to remove the event listener once you have finished working with the realtime data or it will continue listening to it.
194194

195-
Auth works exactly the same as with non-realtime data, you only need to provide the `auth` parameter with a valid `idToken` in the URL.
195+
Auth works exactly the same as with non-realtime data, you only need to provide the `auth` parameter with a valid `authToken` in the URL.
196196

197197
## Modyfing the Database
198198

@@ -337,12 +337,12 @@ For example, we want that each user has their independent journal that they can
337337
}
338338
```
339339

340-
When you want to modify or read their journal you need to specify the users's `localId` (known as `uid` inside the rules) and `idToken` as part of the URL.
340+
When you want to modify or read their journal you need to specify the users's `localId` (known as `uid` inside the rules) and `authToken` as part of the URL.
341341

342342
```actionscript
343-
private function loadPrivateJournal(localId:String, idToken:String):void
343+
private function loadPrivateJournal(localId:String, authToken:String):void
344344
{
345-
var request:URLRequest = new URLRequest("https://<YOUR-PROJECT-ID>.firebaseio.com/journals/"+localId+".json?auth="+idToken);
345+
var request:URLRequest = new URLRequest("https://<YOUR-PROJECT-ID>.firebaseio.com/journals/"+localId+".json?auth="+authToken);
346346
347347
var loader:URLLoader = new URLLoader();
348348
loader.addEventListener(flash.events.Event.COMPLETE, journalLoaded);
@@ -356,6 +356,8 @@ private function journalLoaded(event:flash.events.Event):void
356356
}
357357
```
358358

359-
The `localId` and `auth` values can be obtained after a successful operation with the `Firebase Auth` service.
359+
The `localId` can be obtained after a successful `Sign In`, `Sign Up` or `Get Account Info` request.
360+
361+
The `auth` value can be obtained after a successful `Refresh Token` request.
360362

361363
For more information on these values you can read the [Firebase Auth guide](./../auth/).

examples/FileManager.mxml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
private var alert:Alert;
1818
private var fileRef:FileReference;
1919
private var profile:Object;
20+
private var authToken:String;
2021
2122
private function goRegisterState():void
2223
{
@@ -101,6 +102,7 @@
101102
{
102103
var rawData:Object = JSON.parse(event.currentTarget.data);
103104
profile = rawData;
105+
authToken = rawData.idToken;
104106
currentState = "ManagerState";
105107
}
106108
@@ -129,7 +131,7 @@
129131
private function refreshTokenLoaded(event:flash.events.Event):void
130132
{
131133
var rawData:Object = JSON.parse(event.currentTarget.data);
132-
profile.idToken = rawData.access_token;
134+
authToken = rawData.access_token;
133135
this.currentState = "ManagerState";
134136
}
135137
@@ -138,7 +140,7 @@
138140
*/
139141
protected function loadFiles():void
140142
{
141-
var request:URLRequest = new URLRequest(IMAGES_URL+"/"+profile.localId+".json?auth="+profile.idToken);
143+
var request:URLRequest = new URLRequest(IMAGES_URL+"/"+profile.localId+".json?auth="+authToken);
142144
143145
var loader:URLLoader = new URLLoader();
144146
loader.addEventListener(flash.events.Event.COMPLETE, filesLoaded);
@@ -194,7 +196,7 @@
194196
195197
private function completeHandler(event:Event):void
196198
{
197-
var header:URLRequestHeader = new URLRequestHeader("Authorization", "Bearer "+profile.idToken);
199+
var header:URLRequestHeader = new URLRequestHeader("Authorization", "Bearer "+authToken);
198200
199201
var request:URLRequest = new URLRequest(STORAGE_URL+"images%2F"+profile.localId+"%2F"+fileRef.name);
200202
request.method = URLRequestMethod.POST;
@@ -226,7 +228,7 @@
226228
var header:URLRequestHeader = new URLRequestHeader("Content-Type", "application/json");
227229
var header2:URLRequestHeader = new URLRequestHeader("X-HTTP-Method-Override", "PATCH");
228230
229-
var request:URLRequest = new URLRequest(IMAGES_URL+"/"+profile.localId+"/"+rawData.generation+".json?auth="+profile.idToken);
231+
var request:URLRequest = new URLRequest(IMAGES_URL+"/"+profile.localId+"/"+rawData.generation+".json?auth="+authToken);
230232
request.data = JSON.stringify(myObject);
231233
request.method = URLRequestMethod.POST;
232234
request.requestHeaders.push(header);
@@ -264,7 +266,7 @@
264266
protected function deleteImage():void
265267
{
266268
var header:URLRequestHeader = new URLRequestHeader("X-HTTP-Method-Override", "DELETE");
267-
var header2:URLRequestHeader = new URLRequestHeader("Authorization", "Bearer "+profile.idToken);
269+
var header2:URLRequestHeader = new URLRequestHeader("Authorization", "Bearer "+authToken);
268270
269271
var request:URLRequest = new URLRequest(STORAGE_URL+formatUrl(filesGrid.selectedItem.name));
270272
trace(request.url);
@@ -283,7 +285,7 @@
283285
//The file has been deleted from Storage, now we delete it from the Database.
284286
var header:URLRequestHeader = new URLRequestHeader("X-HTTP-Method-Override", "DELETE");
285287
286-
var request:URLRequest = new URLRequest(IMAGES_URL+"/"+profile.localId+"/"+filesGrid.selectedItem.generation+".json?auth="+profile.idToken);
288+
var request:URLRequest = new URLRequest(IMAGES_URL+"/"+profile.localId+"/"+filesGrid.selectedItem.generation+".json?auth="+authToken);
287289
request.method = URLRequestMethod.POST;
288290
request.requestHeaders.push(header);
289291

examples/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ You will only require the following Database Rules:
4040

4141
## FileManager.mxml
4242

43-
An Apache Flex example that demonstrates how to use Firebase Auth, Firebase Storage and Firebase Database to store and manage user images. Every user will have their own private folder where they will be able to upload, doanload and delete their images.
43+
An Apache Flex example that demonstrates how to use Firebase Auth, Firebase Storage and Firebase Database to store and manage user images.
44+
Every user will have their own private folder where they will be able to upload, download and delete their images.
4445

4546
You will require the following Database Rules:
4647

examples/SimpleChat.mxml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
1414
private var messagesStream:URLStream;
1515
private var profile:Object;
16-
16+
private var authToken:String;
17+
1718
private function goRegisterState():void
1819
{
1920
this.currentState = "RegisterState";
@@ -94,6 +95,7 @@
9495
{
9596
var rawData:Object = JSON.parse(event.currentTarget.data);
9697
profile = rawData;
98+
authToken = rawData.idToken;
9799
currentState = "ChatState";
98100
}
99101
@@ -122,7 +124,7 @@
122124
private function refreshTokenLoaded(event:flash.events.Event):void
123125
{
124126
var rawData:Object = JSON.parse(event.currentTarget.data);
125-
profile.idToken = rawData.access_token;
127+
authToken = rawData.access_token;
126128
this.currentState = "ChatState";
127129
}
128130
@@ -132,7 +134,7 @@
132134
private function loadRealtime():void
133135
{
134136
var header:URLRequestHeader = new URLRequestHeader("Accept", "text/event-stream");
135-
var request:URLRequest = new URLRequest(CHATROOM_URL+'.json?auth='+profile.idToken);
137+
var request:URLRequest = new URLRequest(CHATROOM_URL+'.json?auth='+authToken);
136138
request.requestHeaders.push(header);
137139
138140
messagesStream = new URLStream();
@@ -214,7 +216,7 @@
214216
myObject.senderName = profile.displayName;
215217
myObject.timestamp = new Date().getTime();
216218
217-
var request:URLRequest = new URLRequest(CHATROOM_URL+".json?auth="+profile.idToken);
219+
var request:URLRequest = new URLRequest(CHATROOM_URL+".json?auth="+authToken);
218220
request.data = JSON.stringify(myObject);
219221
request.method = URLRequestMethod.POST;
220222

0 commit comments

Comments
 (0)