public static async Task <string> AnonLogin() { var authProvider = new FirebaseAuthProvider(new FirebaseConfig("AIzaSyDlrs12gBooCtCtg6SXVG2xP3BE-jYXk7g")); var auth = await authProvider.SignInAnonymouslyAsync(); return(auth.FirebaseToken); }
private async Task Login(FirebaseAuthProvider authProvider) { //var facebookAccessToken = "<login with facebook and get oauth access token>"; //_authLink = await authProvider.SignInWithOAuthAsync(FirebaseAuthType.Facebook, facebookAccessToken); // Enable anonymous authentication in your Firebase panel. _authLink = await authProvider.SignInAnonymouslyAsync(); }
/// <inheritdoc/> public IObservable <Unit> SignInAnonymously() { return(_authProvider .SignInAnonymouslyAsync() .ToObservable() .Do(authLink => AuthLink = authLink) .SelectMany(authLink => SaveAccount(authLink))); }
public void LinkAccountsFacebookTest() { var authProvider = new FirebaseAuthProvider(new FirebaseConfig(ApiKey)); var auth = authProvider.SignInAnonymouslyAsync().Result; var newAuth = auth.LinkToAsync(FirebaseAuthType.Facebook, FacebookAccessToken).Result; newAuth.User.LocalId.Should().Be(auth.User.LocalId); newAuth.User.FirstName.Should().BeEquivalentTo(FacebookTestUserFirstName); newAuth.FirebaseToken.Should().NotBeNullOrWhiteSpace(); }
public void LinkAccountsTest() { var authProvider = new FirebaseAuthProvider(new FirebaseConfig(ApiKey)); var email = $"abcd{new Random().Next()}@test.com"; var auth = authProvider.SignInAnonymouslyAsync().Result; var newAuth = auth.LinkToAsync(email, "test1234").Result; newAuth.User.Email.Should().BeEquivalentTo(email); newAuth.User.LocalId.Should().Be(auth.User.LocalId); newAuth.FirebaseToken.Should().NotBeNullOrWhiteSpace(); }
public static async Task Main(string[] args) { try { var apiKey = "AIzaSyAf3zX8rG4hGfjLQK4Er61bTW7cQjTptgE"; // your app secret var firebaseAuthProvider = new FirebaseAuthProvider(new FirebaseConfig(apiKey)); var auth = await firebaseAuthProvider.SignInAnonymouslyAsync(); var firebaseClient = new FirebaseClient( "https://barontest-152eb.firebaseio.com/", new FirebaseOptions { AuthTokenAsyncFactory = () => Task.FromResult(auth.FirebaseToken.ToString()) }); var notifications = firebaseClient.Child("notifications"); //delte old records await notifications.DeleteAsync(); var list = new List <Notification> { new Notification { IsError = false, Message = "This is a test", Channel = "Test_Channel", Id = 1 }, new Notification { IsError = false, Message = "Empty_Channel (will not show)", Channel = "Empty_Channel", Id = 2 }, new Notification { IsError = true, Message = "Error: NULL stuff", Channel = "Test_Channel", Id = 3 }, new Notification { IsError = false, Message = "more test", Channel = "Test_Channel", Id = 4 }, }; Console.WriteLine("Start"); foreach (var item in list) { await Task.Delay(5 * 1000); item.CreatedOn = DateTime.Now; var newNode = await notifications.PostAsync(item); Console.WriteLine($"Posted {item.Message}"); } Console.WriteLine("End"); } catch (Exception e) { throw; } }
public static async Task <String> getDoc(Stream fileStream, String fileName, String apiKey) { var auth = new FirebaseAuthProvider(new FirebaseConfig(apiKey)); var login = await auth.SignInAnonymouslyAsync(); var task = new Firebase.Storage.FirebaseStorage("tayduky-d785d.appspot.com", new Firebase.Storage.FirebaseStorageOptions { AuthTokenAsyncFactory = () => Task.FromResult(login.FirebaseToken) }).Child("docs").Child(fileName).PutAsync(fileStream); return(await task); }
public IActionResult LinkAccountsTwitter(string returnUrl = null) { var authProvider = new FirebaseAuthProvider(new FirebaseConfig(ApiKey)); var auth = authProvider.SignInAnonymouslyAsync().Result; var newAuth = auth.LinkToAsync(FirebaseAuthType.Twitter, TwitterAccessToken).Result; newAuth.User.LocalId.Should().Be(auth.User.LocalId); newAuth.User.FirstName.Should().BeEquivalentTo(FacebookTestUserFirstName); newAuth.FirebaseToken.Should().NotBeNullOrWhiteSpace(); ViewData["ReturnUrl"] = returnUrl; return(View()); }
private async Task <FirebaseClient> Initialize() { var authProvider = new FirebaseAuthProvider(new FirebaseConfig("AIzaSyD8cbGyYVO2WzGIOTnN9VYWRa0aJKP9KDs")); //var facebookAccessToken = "dvnu1F1OjLSA4pYDJN-tq4EJ"; var auth = await authProvider.SignInAnonymouslyAsync(); var fb = new FirebaseClient(BACKEND_URL, new FirebaseOptions { AuthTokenAsyncFactory = () => Task.FromResult(auth.FirebaseToken) }); return(fb); }
private async Task Init() { var apiKey = "AIzaSyAf3zX8rG4hGfjLQK4Er61bTW7cQjTptgE"; // your app secret var firebaseAuthProvider = new FirebaseAuthProvider(new FirebaseConfig(apiKey)); var auth = await firebaseAuthProvider.SignInAnonymouslyAsync(); firebaseClient = new FirebaseClient( "https://barontest-152eb.firebaseio.com/", new FirebaseOptions { AuthTokenAsyncFactory = () => Task.FromResult(auth.FirebaseToken.ToString()) }); notifications = firebaseClient.Child("notifications"); await notifications.DeleteAsync(); }
public async void LoginAnonymousUser(System.Action <FirebaseCredentials> onLogin, System.Action <string> onError) { onLoginSuccess = onLogin; if (Application.isEditor) // Use unofficial firebase.NET SDK (which only works in editor/standalone.) { FirebaseAuthLink auth = await authProvider.SignInAnonymouslyAsync(); CurrentAuth = new FirebaseCredentials(auth.FirebaseToken, true); onLoginSuccess(CurrentAuth); } else { LoginAnonymously(); // login via JS firebase sdk (authplugin.jslib) } }
static async Task Main(string[] args) { var authProvider = new FirebaseAuthProvider(new FirebaseConfig("AIzaSyDXyczRuaZWskx43U-Pamzyw1YaUag79lY")); var sign = await authProvider.SignInAnonymouslyAsync(); var firebase = new FirebaseClient("https://github-issue-bot.firebaseio.com", new FirebaseOptions { AuthTokenAsyncFactory = () => Task.FromResult(sign.FirebaseToken) }); var child = firebase.Child("issues"); var issue = new Issue { Title = "Title1", Label = "Label1" }; var json = JsonConvert.SerializeObject(issue); await child.PostAsync(json); }
public static async Task <String> getFile(Stream fileStream, String fileName) { String apiKey = "AIzaSyD4witV5uIhlnYtWPZ2ZPNfQNh9V-0_RBU"; var auth = new FirebaseAuthProvider(new FirebaseConfig(apiKey)); var login = await auth.SignInAnonymouslyAsync(); var task = new Firebase.Storage.FirebaseStorage("hci-project-281007.appspot.com", new Firebase.Storage.FirebaseStorageOptions { AuthTokenAsyncFactory = () => Task.FromResult(login.FirebaseToken) }) .Child("image") .Child(fileName) .PutAsync(fileStream); // Track progress of the upload task.Progress.ProgressChanged += (s, e) => Console.WriteLine($"Progress: {e.Percentage} %"); // Await the task to wait until upload is completed and get the download url return(await task); }
static void Main(string[] args) { Task.Run(async() => { try { // var config = { // apiKey: "AIzaSyAf3zX8rG4hGfjLQK4Er61bTW7cQjTptgE", // authDomain: "barontest-152eb.firebaseapp.com", // databaseURL: "https://barontest-152eb.firebaseio.com", // projectId: "barontest-152eb", // storageBucket: "barontest-152eb.appspot.com", // messagingSenderId: "592512603881" //}; var apiKey = "AIzaSyAf3zX8rG4hGfjLQK4Er61bTW7cQjTptgE"; // your app secret var firebaseAuthProvider = new FirebaseAuthProvider(new FirebaseConfig(apiKey)); var auth = await firebaseAuthProvider.SignInAnonymouslyAsync(); var firebaseClient = new FirebaseClient( "https://barontest-152eb.firebaseio.com/", new FirebaseOptions { AuthTokenAsyncFactory = () => Task.FromResult(auth.FirebaseToken.ToString()) }); var users = firebaseClient.Child("users_list"); var usersCollection = await users .OrderByKey() .LimitToFirst(1) .OnceAsync <UserNode>(); var user = usersCollection.ToList().First(); var conversations = firebaseClient.Child("conversations"); var conversationsHistory = new Dictionary <string, ConverstionNode>(); var conversationsList = await conversations .OrderByKey() .OnceAsync <ConverstionNode>(); foreach (var conversation in conversationsList) { Console.WriteLine($"{conversation.Key} is {conversation.Object.ToString()}"); conversationsHistory.Add(conversation.Key, conversation.Object); } // add new item to list of data and let the client generate new key for you (done offline) var newNode = await conversations.PostAsync(new ConverstionNode { date = DateTime.Now.ToString("dd/MM/yyyy HH:mm"), username = user.Object.name, text = $"hello to the first userP {user.Object.name} [{DateTime.Now.Ticks}]" }); var obs = conversations.AsObservable <ConverstionNode>(); obs.Where(c => !conversationsHistory.ContainsKey(c.Key)) .Subscribe(f => Console.WriteLine($"after insert: {f.Key}: {f.Object.ToString()}")); //// add new item directly to the specified location (this will overwrite whatever data already exists at that location) //await firebase // .Child("dinosaurs") // .Child("t-rex") // .PutAsync(new Dinosaur()); //// delete given child node //await firebase // .Child("dinosaurs") // .Child("t-rex") // .DeleteAsync(); } catch (Exception ex) { throw; } }).Wait(); Console.ReadLine(); }
public FirebaseManager() { if (InfoImportClass.GetFirebaseJson(out string jsonString)) { using (JsonDocument jsonDocument = JsonDocument.Parse(jsonString)) { JsonElement jsonRoot = jsonDocument.RootElement; if (jsonRoot.TryGetProperty("project_info", out JsonElement json_project_info)) { if (json_project_info.TryGetProperty("firebase_url", out JsonElement firebaseurl)) { firebase_url = firebaseurl.ToString(); } } if (jsonRoot.TryGetProperty("client", out JsonElement json_client)) { // TODO : find a new method to get api key from json. This hurts . . . // Because a firebase project can have multiple apps, a client section of the json // is an array that must be parsed to make sure we can get the correct authorization // key to connect to the firebase project and database. This is important as apps // save unique variations of access/auth permissions in terms of connection/login, reading, // and writing to any specific server-side containers, such as the database. // Rather than doing this, perhaps making a class that reads all the service data // into memory would be easier? foreach (JsonElement jsonElement in json_client.EnumerateArray()) { if (jsonElement.TryGetProperty("client_info", out JsonElement json_client_info)) { if (json_client_info.TryGetProperty("android_client_info", out JsonElement json_android_client_info)) { if (json_android_client_info.TryGetProperty("package_name", out JsonElement json_package_name)) { if (json_package_name.ToString() == "Syno.DiscordBot") { if (jsonElement.TryGetProperty("api_key", out JsonElement json_api_key)) { foreach (JsonElement keyElement in json_api_key.EnumerateArray()) { if (keyElement.TryGetProperty("current_key", out JsonElement json_current_key)) { api_key = json_current_key.ToString(); } } } } } } } } } } } IsValid = firebase_url != "" && api_key != ""; if (IsValid) { FirebaseSignIn firebaseSignIn = new FirebaseSignIn(); firebaseSignIn.ShowDialog(); if (firebaseSignIn.username != "" && firebaseSignIn.password != "") { username = firebaseSignIn.username; password = firebaseSignIn.password; firebaseClient = new FirebaseClient( firebase_url, new FirebaseOptions { AuthTokenAsyncFactory = () => LoginAsync() }); firebaseAuthProvider = new FirebaseAuthProvider(new FirebaseConfig(api_key)); try { firebaseAuthProvider.SignInWithEmailAndPasswordAsync(username, password).ContinueWith(x => firebaseAuthLink = x.Result).Wait(); } catch (Exception e) { Console.WriteLine("Could not log in with syno account to firebase authentication, logging in as anon."); Console.WriteLine("Exception : \n " + e.Message); firebaseAuthProvider.SignInAnonymouslyAsync().ContinueWith(x => firebaseAuthLink = x.Result).Wait(); } string jsonData = JsonSerializer.Serialize(Program.abilityLibrary.GetAbility("testname1")); firebaseClient.Child("Abilities").PostAsync <Dictionary <string, Ability> >(Program.abilityLibrary.GetAbilitiesAsDictionary()); //firebaseClient.Child("Abilities").PostAsync<Ability>(Program.abilityLibrary.GetAbility("testname2")); //firebaseClient.Child("Abilities").PostAsync<Ability>(Program.abilityLibrary.GetAbility("testname3")); //firebaseClient.Child("Abilities").PostAsync<Ability>(Program.abilityLibrary.GetAbility("testname4")); //string curDir = Directory.GetCurrentDirectory() + "\\Lists\\"; // //if (!Directory.Exists(curDir)) //{ // Directory.CreateDirectory(curDir); // Console.WriteLine("Error! List Folder could not be found! Made directory at " + curDir); //} // //string JsonString = System.IO.File.ReadAllText(curDir + "AbilityLibrary.txt"); // //firebaseClient.Child("dinosours").Child(userID).PostAsync(JsonString); //Task.Delay(10000); //TestData(); } } }
public async Task <int> Send(string country, string city, string postalCode, string isp, string type, string speed, string pingFile, string speedFile) { documentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments).ToString(); try { // Authenticate Anonymously with Firebase var authProvider = new FirebaseAuthProvider(new FirebaseConfig("AIzaSyAjc7Gk9LydAEKG--oCeeuNM0YG4XGihDg")); var auth = await authProvider.SignInAnonymouslyAsync(); var firebase = new FirebaseClient("https://neasure-5ed3e.firebaseio.com/", new FirebaseOptions { AuthTokenAsyncFactory = () => Task.FromResult(auth.FirebaseToken) }); // Upload Ping file to Bucket UploadToBucket(pingFile, "ping_", auth); // Upload Speed file to Bucket UploadToBucket(speedFile, "speed_", auth); // Upload Information to Database var data = new Data { country = country, city = city, postalCode = postalCode, ISP = isp, type = type, speed = speed, #if DEBUG debug = true #else debug = false #endif }; await firebase.Child("data").Child(auth.User.LocalId).PostAsync(data); // Write sent Data into File and upload to Firebase using (var surveyWriter = File.AppendText(documentsFolder + "\\Neasure\\survey_" + auth.User.LocalId + ".txt")) { surveyWriter.WriteLine("Data Sent to Firebase: "); surveyWriter.WriteLine("Country: " + country); surveyWriter.WriteLine("City: " + city); surveyWriter.WriteLine("Postal Code: " + postalCode); surveyWriter.WriteLine("ISP: " + isp); surveyWriter.WriteLine("Internet Type: " + type); surveyWriter.WriteLine("Internet Speed: " + speed); #if DEBUG surveyWriter.WriteLine("Warning: Result Created by Debug Build"); #endif } // Upload Survey to Bucket UploadToBucket(documentsFolder + "\\Neasure\\survey_" + auth.User.LocalId + ".txt", "survey_", auth); return(1); } catch (Exception ex) { MessageBox.Show(Resources.Error_FirebaseSend + ex.Message, Resources.ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); return(0); } }