private string parseFacebookUserIdFromSettings(ACAccount account) { SLRequest sl = SLRequest.Create(SLServiceKind.Facebook, SLRequestMethod.Get, new NSUrl("https://graph.facebook.com/me"), null); sl.Account = account; AutoResetEvent completedEvent = new AutoResetEvent(false); var id = string.Empty; sl.PerformRequest((data, response, error) => { if (error == null) { NSError parseError; NSDictionary jsonDict = (NSDictionary)NSJsonSerialization.Deserialize(data, 0, out parseError); if (jsonDict != null) { NSObject obj = jsonDict.ValueForKey(new NSString("id")); id = obj?.ToString(); } } completedEvent.Set(); }); completedEvent.WaitOne(); return(id); }
/// <summary> U3DXT internal. </summary> protected void _Init() { _service.RequestAccessToAccounts(_accountType, _options, delegate(bool granted, NSError error) { CoreXT.RunOnMainThread(delegate() { if (granted) { var accounts = _service.FindAccounts(_accountType); if ((accounts != null) && (accounts.Length > 0)) { _account = accounts[0] as ACAccount; if (_initializationCompletedHandlers != null) { _initializationCompletedHandlers(this, EventArgs.Empty); } return; } } _account = null; if (_initializationFailedHandlers != null) { _initializationFailedHandlers(this, (error != null) ? new U3DXTErrorEventArgs(error) : new U3DXTErrorEventArgs(0, "", "No account setup or permission denied.")); } }); }); }
private async Task LoadAccountAsync() { if (account != null) { return; } if (loadingAccount != null) { await Task.WhenAny(loadingAccount); return; } Debug.WriteLine("Accessing Twitter Account..."); WorkStarted?.Invoke(this, EventArgs.Empty); var type = accountStore.FindAccountType(ACAccountType.Twitter); var result = await accountStore.RequestAccessAsync(type, null); if (result.Item1) { account = accountStore.Accounts[0]; Debug.WriteLine($"Access granted: {account.Username}"); } else { Debug.WriteLine("Access denied!"); } WorkFinished?.Invoke(this, EventArgs.Empty); loadingAccount = null; }
public override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); // Update UI based on state SendTweet.Enabled = isTwitterAvailable; RequestTwitterTimeline.Enabled = false; PostToFacebook.Enabled = isFacebookAvailable; RequestFacebookTimeline.Enabled = false; // Initialize Twitter Account access var accountStore = new ACAccountStore(); var accountType = accountStore.FindAccountType(ACAccountType.Twitter); // Request access to Twitter account accountStore.RequestAccess(accountType, null, (granted, error) => { // Allowed by user? if (granted) { // Get account if (accountStore.Accounts.Length == 0) { return; } twitterAccount = accountStore.Accounts [accountStore.Accounts.Length - 1]; InvokeOnMainThread(() => { // Update UI RequestTwitterTimeline.Enabled = true; }); } }); // Initialize facebook Account access var options = new AccountStoreOptions(); options.FacebookAppId = ""; // Enter your specific Facebook App ID here accountType = accountStore.FindAccountType(ACAccountType.Facebook); // Request access to Facebook account accountStore.RequestAccess(accountType, options, (granted, error) => { // Allowed by user? if (granted) { if (accountStore.Accounts.Length == 0) { return; } // Get account facebookAccount = accountStore.Accounts [accountStore.Accounts.Length - 1]; InvokeOnMainThread(() => { // Update UI RequestFacebookTimeline.Enabled = true; }); } }); }
public ACAccountWrapper (ACAccount account, ACAccountStore store) { if (account == null) { throw new ArgumentNullException ("account"); } this.ACAccount = account; this.store = store; }
public ACAccountWrapper(ACAccount account, ACAccountStore store) { if (account == null) { throw new ArgumentNullException("account"); } this.ACAccount = account; this.store = store; }
public ACAccountWrapper (ACAccount account, ACAccountStore store) { if (account == null) { throw new ArgumentNullException ("account"); } this.ACAccount = account; this.store = store; this.isTwitterAccount = account.AccountType.Identifier == store.FindAccountType (ACAccountType.Twitter).Identifier; }
public ACAccountWrapper(ACAccount account, ACAccountStore store) { if (account == null) { throw new ArgumentNullException("account"); } this.ACAccount = account; this.store = store; this.isTwitterAccount = account.AccountType.Identifier == store.FindAccountType(ACAccountType.Twitter).Identifier; }
public override void ViewWillAppear (bool animated) { base.ViewWillAppear (animated); // Update UI based on state SendTweet.Enabled = isTwitterAvailable; RequestTwitterTimeline.Enabled = false; PostToFacebook.Enabled = isFacebookAvailable; RequestFacebookTimeline.Enabled = false; // Initialize Twitter Account access var accountStore = new ACAccountStore (); var accountType = accountStore.FindAccountType (ACAccountType.Twitter); // Request access to Twitter account accountStore.RequestAccess (accountType, null, (granted, error) => { // Allowed by user? if (granted) { // Get account if (accountStore.Accounts.Length == 0) return; twitterAccount = accountStore.Accounts [accountStore.Accounts.Length - 1]; InvokeOnMainThread (() => { // Update UI RequestTwitterTimeline.Enabled = true; }); } }); // Initialize facebook Account access var options = new AccountStoreOptions (); options.FacebookAppId = ""; // Enter your specific Facebook App ID here accountType = accountStore.FindAccountType (ACAccountType.Facebook); // Request access to Facebook account accountStore.RequestAccess (accountType, options, (granted, error) => { // Allowed by user? if (granted) { if (accountStore.Accounts.Length == 0) return; // Get account facebookAccount = accountStore.Accounts [accountStore.Accounts.Length - 1]; InvokeOnMainThread (() => { // Update UI RequestFacebookTimeline.Enabled = true; }); } }); }
public static Task<ACAccountCredentialRenewResult> RenewCredentialsAsync (this ACAccountStore store, ACAccount account) { TaskCompletionSource<ACAccountCredentialRenewResult> tcs = new TaskCompletionSource<ACAccountCredentialRenewResult> (); store.RenewCredentials (account, delegate (ACAccountCredentialRenewResult arg1, NSError arg2) { if (arg2 != null) { tcs.SetException (new NSErrorException (arg2)); } else { tcs.SetResult (arg1); } }); return tcs.Task; }
public static void getAccount() { if (twitterAccount != null) return; ACAccountStore accountStore = new ACAccountStore(); ACAccountType accountTypeTwitter = accountStore.FindAccountType(ACAccountType.Twitter); accountStore.RequestAccess(accountTypeTwitter, (granted, error) => { if (!granted) return; ACAccount[] accounts = accountStore.FindAccounts(accountTypeTwitter); if (accounts.Length > 0) twitterAccount = accounts[0]; }); }
private void tryNextAccount(int index = 0) { ACAccount[] accounts = accountStore.FindAccounts(accountStore.FindAccountType(ACAccountType.Twitter)); ACAccount account = accounts[index]; Notification n = new Notification( LocalisationManager.GetString(OsuString.TwitterLinkQuestion), string.Format(LocalisationManager.GetString(OsuString.TwitterLinkQuestionDetails), account.Username), NotificationStyle.YesNo, delegate(bool resp) { if (!resp) { if (index == accounts.Length - 1) //exhausted our options. { handleManualAuth(); } else { tryNextAccount(index + 1); } return; } NSDictionary properties = account.GetDictionaryOfValuesFromKeys(new NSString[] { new NSString("properties") }); string twitter_id = properties.ObjectForKey(new NSString("properties")).ValueForKey(new NSString("user_id")).ToString(); //works!! { Notification n1 = new Notification(LocalisationManager.GetString(OsuString.TwitterSuccess), string.Format(LocalisationManager.GetString(OsuString.TwitterSuccessDetails), account.Username), NotificationStyle.Okay, null); GameBase.Notify(n1); GameBase.Config.SetValue <string>("username", account.Username); GameBase.Config.SetValue <string>("hash", "ios-" + account.Identifier); GameBase.Config.SetValue <string>("twitterId", twitter_id); GameBase.Config.SaveConfig(); Director.ChangeMode(Director.CurrentOsuMode); } }); GameBase.Notify(n); }
private void _Request(string url, SLRequestMethod method, Dictionary <object, object> parameters, Action <object, NSHTTPURLResponse, NSError> callback) { _service.RequestAccessToAccounts(_accountType, _options, delegate(bool granted, NSError error) { CoreXT.RunOnMainThread(delegate() { if (granted) { var account = _service.FindAccounts(_accountType)[0] as ACAccount; var request = SLRequest.Request( _serviceType, method, new NSURL(url), parameters); request.account = account; // Debug.Log("prepared url: " + request.PreparedURLRequest().URL().AbsoluteString() + "\n" + Json.Serialize(request.PreparedURLRequest().AllHTTPHeaderFields()) // + "\n" + request.PreparedURLRequest().HTTPBody().ToByteArray().ToStraightString()); request.PerformRequest(delegate(NSData responseData, NSHTTPURLResponse urlResponse, NSError error2) { object obj = null; var response = Encoding.UTF8.GetString(responseData.ToByteArray()); try { obj = Json.Deserialize(response); } catch (Exception) { obj = response; } callback(obj, urlResponse, error2); callback = null; }); parameters = null; account = null; request = null; } else { callback(null, null, error); parameters = null; callback = null; } }); }); }
/// <summary> U3DXT internal. </summary> protected void _Init() { _service.RequestAccessToAccounts(_accountType, _options, delegate(bool granted, NSError error) { if (granted) { var accounts = _service.FindAccounts(_accountType); if ((accounts != null) && (accounts.Length > 0)) { _account = accounts[0] as ACAccount; if (_initializationCompletedHandlers != null) _initializationCompletedHandlers(this, EventArgs.Empty); return; } } _account = null; if (_initializationFailedHandlers != null) _initializationFailedHandlers(this, (error != null) ? new U3DXTErrorEventArgs(error) : new U3DXTErrorEventArgs(0, "", "No account setup or permission denied.")); }); }
public void TestFacebookAuth() { var doneEvent = new ManualResetEvent(false); var accountStore = new ACAccountStore(); var accountType = accountStore.FindAccountType(ACAccountType.Facebook); var options = new AccountStoreOptions(); options.FacebookAppId = FacebookAppId; options.SetPermissions(ACFacebookAudience.Friends, new [] { "email" }); var success = true; ACAccount account = null; accountStore.RequestAccess(accountType, options, (result, error) => { success = result; if (success) { var accounts = accountStore.FindAccounts(accountType); account = accounts != null && accounts.Length > 0 ? accounts[0] : null; } else { Log.W(Tag, "Facebook Login needed. Go to Settings > Facebook and login."); Log.E(Tag, "Facebook Request Access Error : " + error); } doneEvent.Set(); }); doneEvent.WaitOne(TimeSpan.FromSeconds(30)); Assert.IsTrue(success); Assert.IsNotNull(account); var token = account.Credential.OAuthToken; Assert.IsNotNull(token); Assert.IsTrue(token.Length > 0); var url = GetReplicationURLWithoutCredentials(); var cookieStore = new CookieStore(); var httpClientFactory = new CouchbaseLiteHttpClientFactory(cookieStore); manager.DefaultHttpClientFactory = httpClientFactory; Replication replicator = database.CreatePushReplication(url); replicator.Authenticator = AuthenticatorFactory.CreateFacebookAuthenticator(token); Assert.IsNotNull(replicator); Assert.IsNotNull(replicator.Authenticator); Assert.IsTrue(replicator.Authenticator is TokenAuthenticator); replicator.Start(); doneEvent.Reset(); Task.Factory.StartNew(() => { var timeout = DateTime.UtcNow + TimeSpan.FromSeconds(30); while (DateTime.UtcNow < timeout) { if (!replicator.active) { break; } System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(10)); } doneEvent.Set(); }); doneEvent.WaitOne(TimeSpan.FromSeconds(35)); var urlStr = url.ToString(); urlStr = urlStr.EndsWith("/") ? urlStr : urlStr + "/"; var cookies = httpClientFactory.GetCookieContainer().GetCookies(new Uri(urlStr)); Assert.IsTrue(cookies.Count == 1); Assert.AreEqual("SyncGatewaySession", cookies[0].Name); }
//private static Account CreateFacebokUser(FBGraphObject graphObject) //{ // return new Account // { // Type = Account.Facebook, // Name = graphObject.ObjectForKey("name").ToString(), // UserId = graphObject.ObjectForKey("id").ToString() // }; //} private static Account CreateFacebookUser(ACAccount arg) { return new Account { Type = Account.Facebook, UserId = arg.Username, Name = arg.UserFullName }; }
private static Account CreateTwitterUser(ACAccount a) { return new Account { UserId = a.AccountDescription, Name = a.UserFullName, Type = Account.Twitter }; }
public static Task <ACAccountCredentialRenewResult> RenewCredentialsAsync(this ACAccountStore store, ACAccount account) { TaskCompletionSource <ACAccountCredentialRenewResult> tcs = new TaskCompletionSource <ACAccountCredentialRenewResult> (); store.RenewCredentials(account, delegate(ACAccountCredentialRenewResult arg1, NSError arg2) { if (arg2 != null) { tcs.SetException(new NSErrorException(arg2)); } else { tcs.SetResult(arg1); } }); return(tcs.Task); }
public void TestFacebookAuth() { var sg = new SyncGateway("http", GetReplicationServer()); using (var remoteDb = sg.CreateDatabase("facebook")) { remoteDb.DisableGuestAccess(); var doneEvent = new ManualResetEvent(false); var accountStore = new ACAccountStore(); var accountType = accountStore.FindAccountType(ACAccountType.Facebook); var options = new AccountStoreOptions(); options.FacebookAppId = FacebookAppId; options.SetPermissions(ACFacebookAudience.Friends, new [] { "email" }); var success = true; ACAccount account = null; accountStore.RequestAccess(accountType, options, (result, error) => { success = result; if (success) { var accounts = accountStore.FindAccounts(accountType); account = accounts != null && accounts.Length > 0 ? accounts[0] : null; } else { Log.W(Tag, "Facebook Login needed. Go to Settings > Facebook and login."); Log.E(Tag, "Facebook Request Access Error : " + error); } doneEvent.Set(); }); doneEvent.WaitOne(TimeSpan.FromSeconds(30)); Assert.IsTrue(success); Assert.IsNotNull(account); var token = account.Credential.OAuthToken; Assert.IsNotNull(token); Assert.IsTrue(token.Length > 0); var url = remoteDb.RemoteUri; var cookieStore = new CookieStore(manager.Directory); var httpClientFactory = new CouchbaseLiteHttpClientFactory(cookieStore); manager.DefaultHttpClientFactory = httpClientFactory; Replication replicator = database.CreatePushReplication(url); replicator.Authenticator = AuthenticatorFactory.CreateFacebookAuthenticator(token); Assert.IsNotNull(replicator); Assert.IsNotNull(replicator.Authenticator); Assert.IsTrue(replicator.Authenticator is TokenAuthenticator); CreateDocuments(database, 20); RunReplication(replicator); var urlStr = url.ToString(); urlStr = urlStr.EndsWith("/") ? urlStr : urlStr + "/"; //var cookies = httpClientFactory.GetCookieContainer().GetCookies(new Uri(urlStr)); //Assert.IsTrue(cookies.Count == 1); //Assert.AreEqual("SyncGatewaySession", cookies[0].Name); } }
private void doSubmission() { int deviceType = 0; #if iOS if (!GameBase.Mapper) { deviceType = (int)osum.Support.iPhone.HardwareDetection.Version; //todo: for iOS5 twitter authentication, we need to double-check we actually have auth. string hash = GameBase.Config.GetValue <string>("hash", null); if (hash == null) { //todo: no twitter auth. are we not submitting anymore? return; } else if (hash.StartsWith("ios-")) { hash = hash.Substring(4); using (ACAccountStore store = new ACAccountStore()) { ACAccount account = store.FindAccount(hash); if (account != null) { //yay, i think. //todo: test that this actually checks grants (it should in theory). } else { GameBase.Notify("Twitter authentication failed. Please visit the options screen to login again."); GameBase.Config.SetValue <string>("username", null); GameBase.Config.SetValue <string>("hash", null); GameBase.Config.SetValue <string>("twitterId", null); GameBase.Config.SaveConfig(); return; } } } string check = CryptoHelper.GetMd5String("moocow" + GameBase.Instance.DeviceIdentifier + RankableScore.count100 + RankableScore.count300 + RankableScore.count50 + RankableScore.countMiss + RankableScore.maxCombo + RankableScore.spinnerBonusScore + RankableScore.comboBonusScore + RankableScore.accuracyBonusScore + RankableScore.Ranking + Path.GetFileName(Player.Beatmap.ContainerFilename) + deviceType + RankableScore.hitScore + (int)Player.Difficulty); string postString = "udid=" + GameBase.Instance.DeviceIdentifier + "&count300=" + RankableScore.count300 + "&count100=" + RankableScore.count100 + "&count50=" + RankableScore.count50 + "&countMiss=" + RankableScore.countMiss + "&maxCombo=" + RankableScore.maxCombo + "&spinnerBonus=" + RankableScore.spinnerBonusScore + "&comboBonus=" + RankableScore.comboBonusScore + "&accuracyBonus=" + RankableScore.accuracyBonusScore + "&hitScore=" + RankableScore.hitScore + "&rank=" + RankableScore.Ranking + "&filename=" + NetRequest.UrlEncode(Path.GetFileName(Player.Beatmap.ContainerFilename)) + "&cc=" + GameBase.Config.GetValue <string>("hash", string.Empty) + "&c=" + check + "&difficulty=" + (int)Player.Difficulty + "&username="******"username", string.Empty) + "&twitterid=" + GameBase.Config.GetValue <string>("twitterId", string.Empty) + "&dt=" + deviceType + "&offset=" + avg; spriteSubmitting = new pSprite(TextureManager.Load(OsuTexture.songselect_audio_preview), FieldTypes.StandardSnapRight, OriginTypes.Centre, ClockTypes.Game, new Vector2(20, 20), 0.999f, true, Color4.White) { ExactCoordinates = false, DimImmune = true, ScaleScalar = 0.7f }; spriteSubmitting.Transform(new TransformationF(TransformationType.Rotation, 0, MathHelper.Pi * 2, Clock.Time, Clock.Time + 1500) { Looping = true }); GameBase.MainSpriteManager.Add(spriteSubmitting); spriteSubmitting.FadeInFromZero(300); StringNetRequest nr = new StringNetRequest("https://www.osustream.com/score/submit.php", "POST", postString); nr.onFinish += delegate(string result, Exception e) { spriteSubmitting.AlwaysDraw = false; if (e == null) { spriteSubmitting.FadeOut(200); spriteSubmitting.ScaleTo(3, 200); spriteSubmitting.Colour = Color4.YellowGreen; } else { spriteSubmitting.FadeOut(1000); spriteSubmitting.ScaleTo(1.2f, 200, EasingTypes.In); spriteSubmitting.Colour = Color4.Red; } if (e == null && result != null && result.StartsWith("message:")) { rankingNotification = new Notification("Ranking", result.Replace("message:", string.Empty), NotificationStyle.Okay); if (finishedDisplaying) { GameBase.Notify(rankingNotification); } } }; NetManager.AddRequest(nr); } #endif }