Overview
AccessToken encapsulates all the data associated with a Facebook user access token: the token string itself, the user and app IDs, the set of granted and declined permissions, and expiry information. The class keeps a global current token in sync with login state and notifies observers when it changes.
| Module | FacebookCore |
| Objective-C name | FBSDKAccessToken |
| Availability | iOS 12+ |
Static properties
The current, active access token for the logged-in user. Set automatically when a user logs in with Facebook Login. Setting this property to
nil marks the user as logged out.Returns
true when current is non-nil and isExpired is false.The cache used to persist and restore the current access token between app launches. The SDK sets this to a
UserDefaults-backed implementation by default.Instance properties
The raw OAuth token string. Pass this value in the
access_token parameter of Graph API requests when you need to supply it explicitly.The Facebook user ID associated with this token.
The Facebook app ID for which this token was issued.
The set of permissions the user has granted. Use
hasGranted(_:) to check for a specific permission.The set of permissions the user explicitly declined during a login flow.
The set of permissions that have expired and must be re-requested.
The date and time when this token expires. After this date
isExpired returns true.The date and time when data access for this token expires. After this date
isDataAccessExpired returns true, even if the token itself is still valid.The date and time when this token was last refreshed.
Returns
true when the current date is past expirationDate.Returns
true when the current date is past dataAccessExpirationDate.Instance methods
hasGranted(_:)
Returns whether the user has granted the given permission.
The permission to check, for example
Permission(stringLiteral: "email").true if permission is in the permissions set.
Static methods
refreshCurrentAccessToken(_:)
Attempts to extend the lifetime of current by making a token refresh request to the Graph API. The completion block receives the updated token or an error.
A closure called when the refresh completes. Receives the connection, the raw response, and any error.
Notifications
| Name | Description |
|---|---|
Notification.Name.AccessTokenDidChange | Posted on the default NotificationCenter whenever AccessToken.current changes. The userInfo dictionary contains AccessTokenChangeNewKey and AccessTokenChangeOldKey for the new and previous token values. |