Skip to content

Commit 4db9bec

Browse files
committed
Added Chat example
1 parent 9b92039 commit 4db9bec

File tree

10 files changed

+411
-11
lines changed

10 files changed

+411
-11
lines changed

auth/README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,12 @@ Note that not all providers return the same information, for example Twitter doe
201201

202202
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.
203203

204+
The `idToken` you receive from this response doesn't work with `auth` requests. You must exchange it for a new one using the next method.
205+
204206
## Refreshing the idToken
205207

206208
By default the `idToken` has an expiration time of 60 minutes, you can reset its expiration by requesting a fresh one.
207-
To refresh an `idToken` you will only need to provide the previous one and specify the `grant_type` as `"authorization_code`.
209+
To refresh an `idToken` you will only need to provide the previous one and specify the `grant_type` as `"authorization_code"`.
208210

209211
```actionscript
210212
private function refreshToken(idToken:String):void
@@ -238,6 +240,19 @@ private function errorHandler(event:flash.events.IOErrorEvent):void
238240
}
239241
```
240242

243+
A successful response will look like the following JSON structure:
244+
245+
```json
246+
{
247+
"access_token": "<A long String>",
248+
"expires_in": "3600",
249+
"token_type": "Bearer",
250+
"refresh_token": "<A long String>",
251+
"id_token": "<A long String>",
252+
"user_id": "ZJ7ud0CEpHYPF6QFWRGTe1U1Gvy2",
253+
"project_id": "545203846422"
254+
}
255+
```
256+
241257
Once you have got the `access_token` you are ready to continue performing secure operations against the Firebase Database and Firebase Storage.
242258

243-
This method applies to both Federated and non Fedarated logins.

auth/email/README.md

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Firebase provides 2 options when you require a way for your users to log in into
55
* Email/Password Auth
66
* Anonymous Auth
77

8-
Firebase also uses the Google Identity Toolkit to achieve this.
8+
Email and Anonymous Auth also uses the Google Identity Toolkit to achieve this.
99

1010
## Getting Started
1111

@@ -78,7 +78,7 @@ 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-
Make sure to save this response inside the app so you can use it later to perform Auth requests and account managing.
81+
The `idToken` received from this response does work for `auth` requests.
8282

8383
## Verifying Credentials (Sign In)
8484

@@ -125,6 +125,8 @@ A successful response will look like the following JSON structure:
125125

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

128+
The `idToken` received from this response doesn't work for `auth` requests. You must refresh the `idToken` to get a functional one (see bottom of this guide).
129+
128130
## Password Reset
129131

130132
To reset a password you only require to provide 2 parameters:
@@ -219,7 +221,7 @@ A successful response will look like the following JSON structure:
219221

220222
An email with instructions will be sent to the desired email address. You can customize the template of emails in the Auth section from the Firebase console.
221223

222-
## Get Account info
224+
## Get Account Info
223225

224226
This method is used for retrieving the logged in user information, very useful to check if a user has confirmed their Email Address.
225227

@@ -382,4 +384,55 @@ A successful response will look like the following JSON structure:
382384
{
383385
"kind": "identitytoolkit#DeleteAccountResponse"
384386
}
387+
```
388+
389+
## Refreshing the idToken
390+
391+
By default the `idToken` has an expiration time of 60 minutes, you can reset its expiration by requesting a fresh one.
392+
To refresh an `idToken` you will only need to provide the previous one and specify the `grant_type` as `"authorization_code"`.
393+
394+
```actionscript
395+
private function refreshToken(idToken:String):void
396+
{
397+
var header:URLRequestHeader = new URLRequestHeader("Content-Type", "application/json");
398+
399+
var myObject:Object = new Object();
400+
myObject.grant_type = "authorization_code";
401+
myObject.code = idToken;
402+
403+
var request:URLRequest = new URLRequest("https://securetoken.googleapis.com/v1/token?key="+FIREBASE_API_KEY);
404+
request.method = URLRequestMethod.POST;
405+
request.data = JSON.stringify(myObject);
406+
request.requestHeaders.push(header);
407+
408+
var loader:URLLoader = new URLLoader();
409+
loader.addEventListener(flash.events.Event.COMPLETE, refreshTokenLoaded);
410+
loader.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
411+
loader.load(request);
412+
}
413+
414+
private function refreshTokenLoaded(event:flash.events.Event):void
415+
{
416+
var rawData:Object = JSON.parse(event.currentTarget.data);
417+
var newIdToken:String = rawData.access_token;
418+
}
419+
420+
private function errorHandler(event:flash.events.IOErrorEvent):void
421+
{
422+
trace(event.currentTarget.data);
423+
}
424+
```
425+
426+
A successful response will look like the following JSON structure:
427+
428+
```json
429+
{
430+
"access_token": "<A long String>",
431+
"expires_in": "3600",
432+
"token_type": "Bearer",
433+
"refresh_token": "<A long String>",
434+
"id_token": "<A long String>",
435+
"user_id": "ZJ7ud0CEpHYPF6QFWRGTe1U1Gvy2",
436+
"project_id": "545203846422"
437+
}
385438
```

database/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ Firebase offers a very flexible and secure way to save text-based data.
44

55
This guide will show some of the most common scenarios and it will explain how to use Rules for your database. It is also written from an ActionScript and SQL perspective.
66

7-
A simple `CRUD` [example](./examples) has been provided for your convenience, it only requires a recent version of `Apache Flex` to compile.
8-
97
## Understanding the Data
108

119
The data saved in the Firebase database is structured like a tree. Each 'branch' can have its own branches and those sub branches can have their own sub branches.
@@ -358,6 +356,6 @@ private function journalLoaded(event:flash.events.Event):void
358356
}
359357
```
360358

361-
The `localId` and `auth` values can be obtained after a successful Sign In or Sign Up request.
359+
The `localId` and `auth` values can be obtained after a successful operation with the `Firebase Auth` service.
362360

363361
For more information on these values you can read the [Firebase Auth guide](./../auth/).
File renamed without changes.
File renamed without changes.

examples/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Examples
2+
3+
In this folder you will find several examples on how to use the Firebase services with ActionScript 3.
4+
5+
It is strongly recommended to use recent versions of `Adobe AIR` and `Apache Flex`.
6+
7+
## SimpleChat.mxml
8+
9+
An Apache Flex example that demonstrates how to use the Firebase Database with realtime data and Email auth. This project makes use of the `Responses.as` file that can be found in the [utils folder](./../utils).
10+
11+
You will require to enable the `Email` provider for your project, you will also require the following rules in your project:
12+
13+
```json
14+
{
15+
"rules": {
16+
"messages": {
17+
".read": "auth != null",
18+
".write": "auth != null"
19+
}
20+
}
21+
}
22+
```
23+
24+
## SimpleCRUD.mxml
25+
26+
An Apache Flex example that demonstrates how to use the Firebase Database with non realtime data. You only require the following rules in your project:
27+
28+
```json
29+
{
30+
"rules": {
31+
"journal": {
32+
".read": "true",
33+
".write": "true"
34+
}
35+
}
36+
}
37+
```
38+
39+
## EmailExample.mxml
40+
41+
An Apache Flex example that demonstrates how to perform most operations from the Email Auth service, you will only require to provide your Firebase API Key.
42+
43+
## FederatedExample.mxml
44+
45+
An Apache Flex example that demonstrates how to perform log-in using Google, Twitter and Facebook providers within the same app, you will only require to provide your Firebase API Key.
File renamed without changes.

0 commit comments

Comments
 (0)