/** * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to use, * copy, modify, and distribute this software in source code or binary form for use * in connection with the web services and APIs provided by Facebook. * * As with any software that integrates with the Facebook platform, your use of * this software is subject to the Facebook Developer Principles and Policies * [http://developers.facebook.com/policy/]. This copyright notice shall be * included in all copies or substantial portions of the software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ namespace Facebook.Unity { using System; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; /// /// Contains the access token and related information. /// public class AccessToken { /// /// Initializes a new instance of the class. /// /// Token string. /// User identifier. /// Expiration time. /// Permissions. public AccessToken( string tokenString, string userId, DateTime expirationTime, IEnumerable permissions) { if (string.IsNullOrEmpty(tokenString)) { throw new ArgumentNullException("tokenString"); } if (string.IsNullOrEmpty(userId)) { throw new ArgumentNullException("userId"); } if (expirationTime == DateTime.MinValue) { throw new ArgumentException("Expiration time is unassigned"); } if (permissions == null) { throw new ArgumentNullException("permissions"); } this.TokenString = tokenString; this.ExpirationTime = expirationTime; this.Permissions = permissions; this.UserId = userId; } /// /// Gets or sets the current access token. /// /// The current access token. public static AccessToken CurrentAccessToken { get; internal set; } /// /// Gets or sets the token string. /// /// The token string. public string TokenString { get; internal set; } /// /// Gets or sets the expiration time. /// /// The expiration time. public DateTime ExpirationTime { get; internal set; } /// /// Gets or sets the list of permissions. /// /// The permissions. public IEnumerable Permissions { get; internal set; } /// /// Gets or sets the user identifier. /// /// The user identifier. public string UserId { get; internal set; } internal string ToJson() { var dictionary = new Dictionary(); dictionary[LoginResult.PermissionsKey] = string.Join(",", this.Permissions.ToArray()); dictionary[LoginResult.ExpirationTimestampKey] = this.ExpirationTime.TotalSeconds().ToString(); dictionary[LoginResult.AccessTokenKey] = this.TokenString; dictionary[LoginResult.UserIdKey] = this.UserId; return MiniJSON.Json.Serialize(dictionary); } } }