/// <summary> /// Shows the Google authentication web view so the user can authenticate /// </summary> async Task ShowGoogleAuthenticationView() { try { var api = new GoogleApi("google", Keys.GoogleApiClientId, Keys.GoogleClientSecret, new NativeMessageHandler()) { Scopes = Keys.GoogleScope.Split(' '), }; if (_doResetWebCache) { _doResetWebCache = false; api.ResetData(); } var account = await api.Authenticate(); if (account != null) { var oauthAccount = (OAuthAccount)account; App.AuthToken = "{0} {1}".Fmt(oauthAccount.TokenType, oauthAccount.Token); await Settings.Instance.Save(); } } catch (Exception e) { Console.WriteLine("**SPORT AUTHENTICATION ERROR**\n\n" + e.GetBaseException()); Insights.Report(e); } }
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { SimpleAuth.OnePassword.Activate(); SimpleAuth.NativeSafariAuthenticator.Activate(); Api.UnhandledException += (sender, e) => { Console.WriteLine(e); }; // create a new window instance based on the screen size Window = new UIWindow(UIScreen.MainScreen.Bounds); Window.RootViewController = new DialogViewController(new RootElement("Simple Auth") { new Section("Google Api") { new StringElement("Authenticate", async() => { try{ var account = await googleApi.Authenticate(); ShowAlert("Success", "Authenticate"); } catch (TaskCanceledException) { ShowAlert("Canceled", ""); } catch (Exception ex) { ShowAlert("Error", ex.ToString()); } }), new StringElement("Log out", () => { googleApi.ResetData(); ShowAlert("Success", "Logged out"); }), }, new Section("Api Key Api") { new StringElement("Get", async() => await RunWithSpinner("Querying", async() => { var account = await apiKeyApi.Get("http://petstore.swagger.io/v2/store/inventory?test=test1"); ShowAlert("Success", "Querying"); })), }, new Section("Basic Auth") { new StringElement("Login to Github", async() => { var account = await basicApi.Authenticate(); ShowAlert("Success", "Authenticated"); }), new StringElement("Log out", () => { basicApi.ResetData(); ShowAlert("Success", "Logged out"); }), } }); // make the window visible Window.MakeKeyAndVisible(); return(true); }
public async Task <MobileServiceUser> AuthenticateWithGoogle() { Account account = null; GoogleApi api = null; try { var scopes = new[] { "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile", }; api = new GoogleApi("google", Keys.GoogleClientId) { ServerClientId = Keys.GoogleServerID, Scopes = scopes, }; account = await api.Authenticate(); var oauth = account as OAuthAccount; var token = account.UserData["ServerToken"]; if (account != null) { var jObject = JObject.Parse($"{{'id_token':'{oauth.IdToken}', 'authorization_code':'{token}'}}"); var usr = await AzureService.Instance.Client.LoginAsync(MobileServiceAuthenticationProvider.Google, jObject); return(usr); } } catch (MobileServiceInvalidOperationException e) { if (e.Response.StatusCode == System.Net.HttpStatusCode.InternalServerError) { if (api != null) { api.ResetData(); return(await AuthenticateWithGoogle()); } } Debug.WriteLine(e); } catch (Exception ex) { Debug.WriteLine(ex); } return(null); }
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { // create a new window instance based on the screen size Window = new UIWindow(UIScreen.MainScreen.Bounds); Window.RootViewController = new DialogViewController(new RootElement("Simple Auth") { new Section("Google Api") { new StringElement("Authenticate", () => { RunWithSpinner("Authenticating", async() => { var account = await googleApi.Authenticate(); ShowAlert("Success", "Authenticate"); }); }), new StringElement("Log out", async() => { googleApi.ResetData(); ShowAlert("Success", "Logged out"); }), }, new Section("Api Key Api") { new StringElement("Get", async() => await RunWithSpinner("Querying", async() => { var account = await apiKeyApi.Get("http://petstore.swagger.io/v2/store/inventory?test=test1"); ShowAlert("Success", "Querying"); })), }, new Section("Basic Auth") { new StringElement("Login to Github", async() => { var account = await basicApi.Authenticate(); ShowAlert("Success", "Authenticated"); }), new StringElement("Log out", async() => { basicApi.ResetData(); ShowAlert("Success", "Logged out"); }), } }); // make the window visible Window.MakeKeyAndVisible(); return(true); }
async public Task LogOut(bool clearCookies) { await AzureService.Instance.Client.LogoutAsync(); App.Instance.CurrentAthlete = null; AuthUserProfile = null; Settings.AccessToken = null; Settings.RefreshToken = null; Settings.ProviderUserId = null; Settings.AzureUserId = null; Settings.AzureAuthToken = null; if (clearCookies) { var api = new GoogleApi("google", Keys.GoogleClientId) { ServerClientId = Keys.GoogleServerID, }; api.ResetData(); Settings.RegistrationComplete = false; } }
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { SimpleAuth.OnePassword.Activate(); SimpleAuth.NativeSafariAuthenticator.Activate(); SimpleAuth.Providers.Google.Init(); googleApi = new GoogleApi("google", "419855213697-t0usvf1n0j1vd9glogcp33b4d2fnfjhn.apps.googleusercontent.com") { ServerClientId = "419855213697-uq56vcune334omgqi51ou7jg08i3dnb1.apps.googleusercontent.com", ForceRefresh = true, Scopes = new [] { "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile" } }; googleApi.ResetData(); apiKeyApi = new ApiKeyApi("myapikey", "api_key", AuthLocation.Query) { BaseAddress = new Uri("http://petstore.swagger.io/v2"), }; Api.UnhandledException += (sender, e) => { Console.WriteLine(e); }; // create a new window instance based on the screen size Window = new UIWindow(UIScreen.MainScreen.Bounds); Window.RootViewController = new DialogViewController(new RootElement("Simple Auth") { new Section("Google Api") { new StringElement("Authenticate", async() => { try{ var account = await googleApi.Authenticate(); ShowAlert("Success", "Authenticate"); } catch (TaskCanceledException) { ShowAlert("Canceled", ""); } catch (Exception ex) { ShowAlert("Error", ex.ToString()); } }), new StringElement("Log out", () => { googleApi.ResetData(); ShowAlert("Success", "Logged out"); }), }, new Section("Api Key Api") { new StringElement("Get", async() => await RunWithSpinner("Querying", async() => { var account = await apiKeyApi.Get("http://petstore.swagger.io/v2/store/inventory?test=test1"); ShowAlert("Success", "Querying"); })), }, new Section("Basic Auth") { new StringElement("Login to Github", async() => { var account = await basicApi.Authenticate(); ShowAlert("Success", "Authenticated"); }), new StringElement("Log out", () => { basicApi.ResetData(); ShowAlert("Success", "Logged out"); }), } }); // make the window visible Window.MakeKeyAndVisible(); return(true); }
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { SimpleAuth.Providers.Google.Init(); googleApi = new GoogleApi("google", "419855213697-t0usvf1n0j1vd9glogcp33b4d2fnfjhn.apps.googleusercontent.com") { ServerClientId = "419855213697-uq56vcune334omgqi51ou7jg08i3dnb1.apps.googleusercontent.com", ForceRefresh = true, Scopes = new [] { "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile" } }; apiKeyApi = new ApiKeyApi("myapikey", "api_key", AuthLocation.Query) { BaseAddress = new Uri("http://petstore.swagger.io/v2"), }; string azureTennant = ""; string azureClientId = ""; azureApi = new ADFSApi("Azure", azureClientId, $"https://login.microsoftonline.com/{azureTennant}/oauth2/authorize", $"https://login.microsoftonline.com/{azureTennant}/oauth2/token", ""); Api.UnhandledException += (sender, e) => { Console.WriteLine(e); }; // create a new window instance based on the screen size Window = new UIWindow(UIScreen.MainScreen.Bounds); Window.RootViewController = new DialogViewController(new RootElement("Simple Auth") { new Section("Google Api") { new StringElement("Authenticate", async() => { try{ var account = await googleApi.Authenticate(); ShowAlert("Success", "Authenticate"); } catch (TaskCanceledException) { ShowAlert("Canceled", ""); } catch (Exception ex) { ShowAlert("Error", ex.ToString()); } }), new StringElement("Log out", () => { googleApi.ResetData(); ShowAlert("Success", "Logged out"); }), }, new Section("Api Key Api") { new StringElement("Get", async() => await RunWithSpinner("Querying", async() => { var account = await apiKeyApi.Get("http://petstore.swagger.io/v2/store/inventory?test=test1"); ShowAlert("Success", "Querying"); })), }, new Section("Basic Auth") { new StringElement("Login to Github", async() => { var account = await basicApi.Authenticate(); ShowAlert("Success", "Authenticated"); }), new StringElement("Log out", () => { basicApi.ResetData(); ShowAlert("Success", "Logged out"); }), }, new Section("Fitbit") { new StringElement("Login to server", async() => { fitBitApi.Scopes = new [] { "profile", "settings" }; var account = await fitBitApi.Authenticate(); ShowAlert("Success", "Authenticated"); }), new StringElement("Call Api", async() => { var devices = await fitBitApi.Get("https://api.fitbit.com/1/user/-/devices.json"); ShowAlert("Success", devices); }), new StringElement("Log out", () => { fitBitApi.ResetData(); ShowAlert("Success", "Logged Out"); }) }, new Section("Azure AD") { new StringElement("Login", async() => { var account = await azureApi.Authenticate(); var userData = await azureApi.Get("https://graph.windows.net/me?api-version=1.6"); ShowAlert("Success", "Authenticated"); }), new StringElement("Log out", () => { azureApi.Logout(); ShowAlert("Success", "Logged out"); }), } }); // make the window visible Window.MakeKeyAndVisible(); return(true); }