How can we achieve single signOn for windows authentication where my two applications which are available on internet are configured in iis for windows authentication. On requesting the url there is a popup of windows authentication, so I want there should not be popup for 2nd application if 1st is authenticated.
I have created two application SSO1 and SSO2 on SSO1 Login page I am writing code
protected void btnLogin_Click(object sender, EventArgs e)
{
if (txtUserName.Text == "test" && txtPassword.Text == "test")
{
string guid = Guid.NewGuid().ToString();
Response.Cookies.Add(new HttpCookie("eNPSAuthToken", guid));
Response.Redirect("Default.aspx");
}
else
Response.Write("Invalid User");
}
On SSO2 application default page I am writing code to check the cookie if available redirect it to default page or else login page of SSO2 application.
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["eNPSAuthToken"] == null)
{
Response.Redirect("Login.aspx");
}
}
I need to host both the application on IIS and enable windows authentication, So I will get login popup of windows authentication, I want to get popup only once, if user is authenticated then for 2nd application popup should not come.
Related
I'm using https://www.pujolsluis.com/google-client-plugin-for-xamarin/ for google sign in xamarin forms. Both Login and Logout methods work fine; but i have to hide the login page after successful login.After opening the app from second time onwards, logout method throws java.Lang.IlegalStateException<Timeout exceeded getting exception details> ,cannot logout.Active token is null.How to handle this exception? How to logout successfully from second time?
Login:
public IGoogleClientManager googleClientManager;
googleClientManager = CrossGoogleClient.Current;
private void google_btn_Clicked(object sender, EventArgs e)
{
if (CrossConnectivity.Current.IsConnected)
{
googleClientManager.LoginAsync();
googleClientManager.OnLogin += OnLoginCompleted;
// CrossGoogleClient.Current.SilentLoginAsync();
// var userToken = CrossGoogleClient.Current.ActiveToken;
}
else
{
DependencyService.Get<IToast>().LongAlert("Check Connection!");
}
}
public async void OnLoginCompleted(object s,
GoogleClientResultEventArgs<GoogleUser> loginEventArgs)
{
if (loginEventArgs.Data != null)
{
GoogleUser googleUser = loginEventArgs.Data;
string google_name = googleUser.Name;
string google_mail = googleUser.Email;
Uri google_img = googleUser.Picture;
googleClientManager.OnLogin -= OnLoginCompleted;
}
}
Logout:
public void Logout()
{
googleClientManager.OnLogout += OnLogoutCompleted;
googleClientManager.Logout(); // throws exception from secondtime after hiding loginpage
}
private void OnLogoutCompleted(object sender, EventArgs loginEventArgs)
{
googleClientManager.OnLogout -= OnLogoutCompleted;
}
You are getting this exception because you are trying to log out of a google client that is no longer connected as the message of the exception states.
Google Client Illegal State Exception Screenshot
To solve this you could do two things, fix the logic in your app to persist the logout state, so you don't try and log out when the user is not actually logged in anymore. Or you could enable the ActiveToken and add an if statement before trying to log out to verify if it's null or not you can do so by following the steps on the getting started guide on the project repo: https://github.com/CrossGeeks/GoogleClientPlugin/blob/master/GoogleClient/docs/GettingStarted.md
Activate ActiveToken Google Client Plugin Guide Screenshot
I have used a WebBrowser control in my windows phone application. Using webbrowser control i am logging into my application. On log-out i simply redirect the user to log-in page again and trying to clear the cache and cookies of the webbrowser control.
mybrowser.ClearCookiesAsync();
mybrowser.ClearInternetCacheAsync();
instead of showing log-in screen, it get the previous credentials and logged-in into the application. Can anyone please help me in clearing the cookies and cache of webbrowser conteol.
Complete code:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
App.AccessToken = "";
myBrowser.Navigate(new Uri(login URL));
}
void Navigating(object sender, NavigatingEventArgs e)
{
if (Login complete)
{
clearCahe();
}
}
public async void clearCahe()
{
await myBrowser.ClearCookiesAsync();
await mybrowser.ClearInternetCacheAsync();
}
async functions are hard to get use to. If you put a break point at
await myBrowser.ClearCookiesAsync(); // put a break point here then step-in (F11 on the keyboard)
You will see that will not actually await and will continue on its merry way.
To fix this you have to do something like this
using System.Threading.Task;
public async Task<bool> clearCahe()
{
await myBrowser.ClearCookiesAsync();
await mybrowser.ClearInternetCacheAsync();
return true;
}
and a calling function that also async
like so
private async void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
await clearCache();
// then navigate the page
}
I am developing a windows 7 phone app where I want a particular page( A privacy policy which the user needs to accept ) to be displayed when the user uses the app for the first time in his phone. Can any one please tell me how to get this done.
Two approaches can be taken for this functionality. The first is to always start at the privacy policy page but override the OnNavigatedTo method to check if the policy has been accepted before. If it has, navigate to your "MainPage". Within the Mainpage, remove all backstack entries.
Privacy Policy Page
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// have the accepted the policy?
var settings = IsolatedStorageSettings.ApplicationSettings;
bool accepted;
if(settings.TryGetValue("PolicyAccepted", out accepted))
{
if (accepted)
{
NavigationService.Navigate(new Uri("MainPage.xaml", UriKind.Relative));
}
}
}
private void OnAcceptButtonClick(object sender, RoutedEventArgs routedEventArgs)
{
var settings = IsolatedStorageSettings.ApplicationSettings;
settings["PolicyAccepted"] = true;
settings.Save();
NavigationService.Navigate(new Uri("MainPage.xaml", UriKind.Relative));
}
Then in your MainPage, remove the backstack
protected override void OnNavigatedTo(NavigationEventArgs e)
{
while (NavigationService.CanGoBack) NavigationService.RemoveBackEntry();
}
The second approach is to is a UriMapper as described in this SO answer.
A possible answer to this question can be found here. As you want your page to open up only once I suggest IsolatedStorageSettings to save a boolean value if the user has accepted the policy or not.
I want to create a login page where the users enters username/password then a web service authenticates and saves an authentication token retrieved from the server.
I want the page view to be notified when the authentication is done successfully.
my question is: how to implement this in MVVM pattern ? I created a class for the model, a class for the model view and a class for the calling and parsing of the web service.
I can't set my ModelView as a DataContext for the page cause there are no controls that bind to the Model's data.
is this pattern an overkill or it can be implemented in another way ? please suggest.
Thanks
I have a login page that is implemented as described here. The login page itself does not have a viewmodel, but it does use a service that I wrote that contains a callback when the login completes. the service also contains other useful info about the user. I think MVVM would have been overkill here.
private void LoginButton_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(EmailTextBox.Text)) return;
if (string.IsNullOrEmpty(PasswordTextBox.Password)) return;
Login();
}
private void Login()
{
if (DeviceNetworkInformation.IsNetworkAvailable == false)
{
MessageBox.Show("I'm having trouble connecting to the internet." + Environment.NewLine + "Make sure you have cell service or are connected to WiFi then try again");
}
else
{
LoginButton.Focus(); // Removes the keyboard
UserProfile.Name = EmailTextBox.Text;
UserProfile.Password = PasswordTextBox.Password;
UserProfile.Current.Login(result =>
{
// callback could be on another thread
Dispatcher.BeginInvoke(() =>
{
// Did the login succeed?
if (result.Result)
{
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
else
{
string message = "Sorry, but I was not able to log in that user. Please make sure the name and password were entered correctly.";
MessageBox.Show(message, "Login failed");
}
});
});
}
}
You need to put ICommands in your ViewModel that point to methods who perform calls your web service, and the elements in your View should bind to those commands to perform actions.
And you need one more boolean property in your viewmodel: IsLoggedIn, that you set to true when the Login call to your webservice returns a success.
Then in your view, you can bind to IsLoggedIn to give feedback to your users.
Note: don't forget to raise PropertyChanged for IsLoggedIn in its setter.
I m my application I want to use Webbrowser which will be using Wifi,after the Webbrower opens the the link (task.URL) ,I want to check what is the response like whether the linked got opened or it failed.How do I do that means get the response ?
WebBrowserTask task = new WebBrowserTask();
task.URL = "https://www.goggle.com/";
task.Show();
kindly help
Thanks.
Usually, to catch this use NavigationFailed event as follow:
void WebPage_Loaded(object sender, RoutedEventArgs e)
{
this.webHome.Navigate(new Uri(www,UriKind.Absolute));
this.webHome.NavigationFailed += webHome_NavigationFailed;
}
void webHome_NavigationFailed(object sender, System.Windows.Navigation.NavigationFailedEventArgs e)
{
this.webHome.NavigateToString("No web page available.");
}