Skip to content

Commit cdd5a1c

Browse files
committed
New Auth fixes.
1 parent 498c70e commit cdd5a1c

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

auth/README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ private function getAccountInfo():void
156156
var myObject:Object = new Object();
157157
myObject.requestUri = requestUri;
158158
myObject.sessionId = sessionId;
159+
myObject.returnSecureToken = true;
159160
160161
var request:URLRequest = new URLRequest(FIREBASE_VERIFY_ASSERTION_URL);
161162
request.method = URLRequestMethod.POST;
@@ -169,10 +170,11 @@ private function getAccountInfo():void
169170
}
170171
```
171172

172-
We created another `URLRequest` with 2 parameters:
173+
We created another `URLRequest` with 3 parameters:
173174

174175
* `requestUri` is the URI that contains the `code`, this code will be parsed by the Google Identity Toolkit service and then used to retrieve the logged in user profile information from the choosen provider.
175176
* `sessionId` is from the very start when we requested the `authUri`.
177+
* `returnSecureToken` is required to obtain a `refreshToken` that will later be exchanged for an `access_token` to authenticate against Firebase Database and Storage.
176178

177179
Now we add the `registerComplete` function that will contain the logged in user information.
178180

@@ -190,8 +192,9 @@ This information is formatted the same for all providers, the most important val
190192

191193
Name | Description
192194
---|---
195+
`providerId`| A unique id assigned for the provider used in the Sign In process, for example: `facebook.com` or `twitter.com`.
193196
`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.
194-
`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`.
197+
`refreshToken`| An identity token that is used to identify the current logged in user. The `refreshToken` is used in further Auth requests such as exchanging it for an `access_token`.
195198
`displayName`| The logged in user full name (Google and Facebook) or their handler in Twitter.
196199
`photoUrl`| The logged in user avatar.
197200
`email`| The logged in user email address.
@@ -203,16 +206,16 @@ Once you have the profile information you might want to save it on an Object tha
203206
## Obtaining and Refreshing an Access Token
204207

205208
By default the `access_token` has an expiration time of 60 minutes, you can reset its expiration by requesting a fresh one.
206-
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"`.
209+
To obtain or refresh an `access_token` you only need to provide a `refreshToken` from a Sign In request and specify the `grant_type` as `"refresh_token"`.
207210

208211
```actionscript
209-
private function refreshToken(idToken:String):void
212+
private function refreshToken(refreshToken:String):void
210213
{
211214
var header:URLRequestHeader = new URLRequestHeader("Content-Type", "application/json");
212215
213216
var myObject:Object = new Object();
214-
myObject.grant_type = "authorization_code";
215-
myObject.code = idToken;
217+
myObject.grant_type = "refresh_token";
218+
myObject.refresh_token = refreshToken;
216219
217220
var request:URLRequest = new URLRequest("https://securetoken.googleapis.com/v1/token?key="+FIREBASE_API_KEY);
218221
request.method = URLRequestMethod.POST;

examples/FederatedCRUD.mxml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
var myObject:Object = new Object();
7676
myObject.requestUri = requestUri;
7777
myObject.sessionId = sessionId;
78+
myObject.returnSecureToken = true;
7879
7980
var request:URLRequest = new URLRequest(FIREBASE_VERIFY_ASSERTION_URL);
8081
request.method = URLRequestMethod.POST;
@@ -93,17 +94,17 @@
9394
var rawData:Object = JSON.parse(event.currentTarget.data);
9495
profile = rawData;
9596
96-
refreshToken(profile.idToken);
97+
refreshToken(profile.refreshToken);
9798
}
9899
99-
private function refreshToken(idToken:String):void
100+
private function refreshToken(refreshToken:String):void
100101
{
101102
var header:URLRequestHeader = new URLRequestHeader("Content-Type", "application/json");
102103
103104
var myObject:Object = new Object();
104-
myObject.grant_type = "authorization_code";
105-
myObject.code = idToken;
106-
105+
myObject.grant_type = "refresh_token";
106+
myObject.refresh_token = refreshToken;
107+
107108
var request:URLRequest = new URLRequest("https://securetoken.googleapis.com/v1/token?key="+FIREBASE_API_KEY);
108109
request.method = URLRequestMethod.POST;
109110
request.data = JSON.stringify(myObject);

examples/FederatedLogin.mxml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@
7070
var myObject:Object = new Object();
7171
myObject.requestUri = requestUri;
7272
myObject.sessionId = sessionId;
73-
73+
myObject.returnSecureToken = true;
74+
7475
var request:URLRequest = new URLRequest(FIREBASE_VERIFY_ASSERTION_URL);
7576
request.method = URLRequestMethod.POST;
7677
request.data = JSON.stringify(myObject);

examples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ An Apache Flex example that demonstrates how to perform log-in using Google, Twi
101101

102102
You will only require to provide your Firebase API Key and enable the providers of your choice.
103103

104-
## ToDo app
104+
## ToDo App
105105
*Main repository: [ToDo App](https://github.com/PhantomAppDevelopment/todo-app)*
106106

107107
ToDo App is a mobile application developed with Starling Framework and FeathersUI. It showcases how to use Firebase services with ActionScript to create simple and secure CRUD system.

0 commit comments

Comments
 (0)