public static Access Authorization(AppLushKey key, Identity identity, bool throwOnError = true) { if (key == null) { throw new ArgumentNullException(nameof(key)); } if (identity == null) { throw new ArgumentNullException(nameof(identity)); } return(Authorization(key, identity.Token, throwOnError)); }
public static Access Authorization(AppLushKey key, string authToken, bool throwOnError = true) { if (key == null) { throw new ArgumentNullException(nameof(key)); } if (authToken == null) { throw new ArgumentNullException(nameof(authToken)); } var input = new Dictionary <string, string>(); input["app_id"] = key.ID.ToString(); input["app_key"] = key.AccessKey; input["auth_token"] = authToken; var text = Http.Post(GatewayURL + "?action=Authorization", null, input); var json = Json.Parse <JsonObject>(text); if (!(bool)json["result"]) { if (throwOnError) { throw new ArgumentException(json["data"]); } return(null); } json = json["data"] as JsonObject; string accessToken = json["access_token"]; string refreshToken = json["refresh_token"]; double seconds = json["expires_in"]; return(new Access(accessToken, refreshToken, DateTime.Now.AddSeconds(seconds))); }