Packagecom.myflashlab.air.extensions.facebook.access
Classpublic class Auth
InheritanceAuth Inheritance flash.events.EventDispatcher

Loging your users to your app is the most important task you may need when working with a facebook extension in your app. This class will provide you everything you would need about logging in and out with letting you know about the permissions that the user has given to you and also this class will provide you with the token id of the current active session in your app. (you may use the token for complex graph API calls.)

What I like to emphasize here is that you should forget the word "login" when working with facebook SDK! because you are actually requesting for permissions from your users. if they grand you with the permissions you are asking, then they can use your app features.

The beauty of this system is that you can easily manage what features your users can have access to based on the permissions they have granded.

The best practice is to ask for more permissions in your app ONLY when you need them. do NOT scare your users too quickly! :)

View the examples

See also

Permissions


Public Properties
 PropertyDefined By
  declinedPermissions : Array
[read-only] returns an array of permissions which your user did NOT allow.
Auth
  isLogin : Boolean
[read-only] indicates if you are already logged in or not.
Auth
  permissions : Array
[read-only] returns an array of permissions which your user has granted to your app.
Auth
  token : String
[read-only] if you are logged in, this will return the token you may find useful in complex graph calls.
Auth
Public Methods
 MethodDefined By
  
logout():void
Call this method to logout.
Auth
  
requestPermission($withPublishPermissions:Boolean, ... rest):Boolean
use this method to login your users to your app based on the list of permissions you need.
Auth
Public Constants
 ConstantDefined By
  WITH_PUBLISH_PERMISSIONS : Boolean = true
[static] Does not work on Android yet!
Auth
  WITH_READ_PERMISSIONS : Boolean = false
[static] read permissions grant you access to different information availble on users facebook account.
Auth
Property Detail
declinedPermissionsproperty
declinedPermissions:Array  [read-only]

returns an array of permissions which your user did NOT allow.


Implementation
    public function get declinedPermissions():Array
isLoginproperty 
isLogin:Boolean  [read-only]

indicates if you are already logged in or not.


Implementation
    public function get isLogin():Boolean
permissionsproperty 
permissions:Array  [read-only]

returns an array of permissions which your user has granted to your app.


Implementation
    public function get permissions():Array
tokenproperty 
token:String  [read-only]

if you are logged in, this will return the token you may find useful in complex graph calls.

IMPORTANT: token expires very often. so when you call the graph, it may return error messages and you should parse the returned json and renew your token if required. renewing the token is easy! simply call the requestPermission method again.


Implementation
    public function get token():String
Method Detail
logout()method
public function logout():void

Call this method to logout. as soon as you call this method, the token value will be nulled.

requestPermission()method 
public function requestPermission($withPublishPermissions:Boolean, ... rest):Boolean

use this method to login your users to your app based on the list of permissions you need.

Parameters

$withPublishPermissions:Boolean
 
... rest — rest

Returns
Boolean — returns true if the method has been called successfully. this does NOT mean that the login process has been completed. to know if the login has been completed, you must use add listeners.
Constant Detail
WITH_PUBLISH_PERMISSIONSConstant
public static const WITH_PUBLISH_PERMISSIONS:Boolean = true

Does not work on Android yet!

WITH_READ_PERMISSIONSConstant 
public static const WITH_READ_PERMISSIONS:Boolean = false

read permissions grant you access to different information availble on users facebook account.

NOTICE: sharing, is completly independent from the login procedure. you will be able to share content without any logging in required at all

Examples
This example will show you how to ask for permissions from your users
     FB.auth.addEventListener(FBEvent.LOGIN_DONE, onLoginSuccess);
     FB.auth.addEventListener(FBEvent.LOGIN_CANCELED, onLoginCanceled);
     FB.auth.addEventListener(FBEvent.LOGIN_ERROR, onLoginError);
     
     // an array of permissions. you can add or remove items from this array anytime you like
     FB.auth.requestPermission(Auth.WITH_READ_PERMISSIONS, Permissions.public_profile, Permissions.user_friends, Permissions.email);
     
     function onLoginSuccess(event:FBEvent):void
     {
         FB.auth.removeEventListener(FBEvent.LOGIN_DONE, onLoginSuccess);
         FB.auth.removeEventListener(FBEvent.LOGIN_CANCELED, onLoginCanceled);
         FB.auth.removeEventListener(FBEvent.LOGIN_ERROR, onLoginError);
         
         trace("onLoginSuccess");
         trace("token = " + FB.auth.token);
         trace("permissions = " + FB.auth.permissions);
         trace("declined Permissions = " + FB.auth.declinedPermissions);
     }
     
     function onLoginCanceled(event:FBEvent):void
     {
         FB.auth.removeEventListener(FBEvent.LOGIN_DONE, onLoginSuccess);
         FB.auth.removeEventListener(FBEvent.LOGIN_CANCELED, onLoginCanceled);
         FB.auth.removeEventListener(FBEvent.LOGIN_ERROR, onLoginError);
         
         trace("onLoginCanceled");
     }
     
     function onLoginError(event:FBEvent):void
     {
         FB.auth.removeEventListener(FBEvent.LOGIN_DONE, onLoginSuccess);
         FB.auth.removeEventListener(FBEvent.LOGIN_CANCELED, onLoginCanceled);
         FB.auth.removeEventListener(FBEvent.LOGIN_ERROR, onLoginError);
         
         trace("onLoginError = " + event.param);
     }