WebView2 - SSO, Recognize Login, or Persist Cookies/Identity - authentication

I am running into an issue, working win WebView2 in a WPF application.
The one complaint we are getting from users is that the MS login gets 'forgotten' after the browser window closes, requiring that they login via a popup MS window on subsequent webview loads, and click on their identity. If a webview2 app that has already stored the user identity is open, it seems to reuse that authentication.
Is there a way to persist that login, so that after the window closes, subsequent windows reuse that login, along with maybe an expiration on the file(s) that have that information?
Some thoughts:
Prevent the deletion of the files providing identity
Launching and hiding a window that would persist the identity (very old-school)
Find a parameter that enables it to login automatically
I've already tried setting the environment variable for AllowSingleSignOnUsingOSPrimaryAccount, but that didn't work.
It is using Fixed Binaries, so passing a relative path.
var options = new CoreWebView2EnvironmentOptions(default, default, default, true);
string installPath = #"./Microsoft.WebView2.FixedVersionRuntime.91.0.864.48.x86";
CoreWebView2Environment env = await CoreWebView2Environment.CreateAsync(installPath, userFolder, options);
await this.webView.EnsureCoreWebView2Async(env);

Related

Persist WkWebView Session

I have a server List in Native. When one of the items on the list is clicked, I am using WKWebView to load an URL from item.
Each of the server have their own login session.
Now when I open one of the server pages in WKWebView and come back to the server list and select the same server again. Instead of using the previous session, it creates a new session for the server. This results in additional license being checked out from the server.
How do I check if there is already a session open and use that session for WKWebView instead of creating a new session every time?

protractor - switch to facebook login screen when testing Oauth2

I'm trying to write e2e login test to my application which uses oauth2.
when clicking the facbook login- another window opened (the facebook login). I'm trying to enter the credentials there.
I'm currently using
browser.driver.switchTo().window();
because it is a new window.
I've read that I can get the name of the window by entering 'window.name' in the console.
when doing that I got '_e_02MT'
I have also tried 'window.document.title' and got 'Facebook'
I've tried the different combinations of
browser.driver.switchTo().window('_e_02MT');
browser.switchTo().window('Facebook');
browser.driver.switchTo().window('Facebook');
and so on
still can't get to that window. I'm getting the error:
NoSuchWindowError: no such window
any ideas?
thanks.
Instead of a name of the window, you need to provide a handle:
browser.getAllWindowHandles().then(function (handles) {
// switch to the popup
browser.switchTo().window(handles[1]);
// do stuff with the popup
// ...
// go back to the main window
browser.switchTo().window(handles[0]);
});

Office 365 JavaScript API, redirect back to WP app after launching Store

I am creating a Windows Phone app using HTML And JavaScript. I am able to add connected services and have selected "Users and Groups" and given it Read permissions.
I am then making the following calls on button click:
var authContext = new O365Auth.Context();
authContext.getIdToken("https://TestDomain.onmicrosoft.com/TestWebApi").then(
function (token){
}
);
Services/Office365/Settings.js has been edited to the following:
Settings.clientId = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
Settings.authUri = "https://login.windows.net/common/";
Settings.redirectUri = "ms-app://s-1-15-2-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx-xxxxxxxxx-xxxxxxxxxx-xxxxxxxxxx/";
I got the redirectUri value by calling the following function:
Windows.Security.Authentication.Web.WebAuthenticationBroker.getCurrentApplicationCallbackUri();
I do get the login screen for my organization and I am able to provide credentials and it tries to redirect it back to my application, but then I get asked the following question:
"You need to install an app for this task. Would you like to search for one in the Store?"
If I click on yes, it takes me to the store and says "No apps found". If I click on no, it doesn't do anything.
How could I possibly get it redirected back to my app?
The connected services experience only works in Multi-device hybrid apps (a.k.a. Cordova), not in Windows Phone apps.

How to Sign-Out from an authenticated ListDataProvider/Authenticator in Windows Phone 8

I am reading a SharePoint list from Office 365 inside a Windows Phone 8 app. My app-code is based on this sample code from Microsoft. It uses
Microsoft.SharePoint.Phone.Application.ListDataProviderBase
Microsoft.SharePoint.Client.ClientContext
Microsoft.SharePoint.Client.Authenticator
The actual problem beeing signout not working!
On the first request to the server, the client asks for authentication and shows a hosted browser window where I can enter my account credentials. I select to stay logged in here.
If i restart the app, it authenticates me without showing the UI again.
I would like to be able to switch user or simply signout leaving no credentials on the phone behind.
I found the following static methods on Authenticator which do not change anything:
Authenticator.ClearAllCookies();
Authenticator.ClearAllCredentials();
Authenticator.ClearAllApplicationSettings();
What is the prefered way to do this?
This is an example of how I am logging out a user in my SP list App for WP8:
App.MainViewModel.IsInitialized = false;
Authenticator.ClearAllCredentials();
App.MainViewModel.Initialize();
MessageBox.Show("You have been successfully logged out, click refresh to login again.");
Your app maybe a little different, but you should at least get to the App and ViewModel to set Initialized as false. I did expxect the App.MainViewModel.Initialize() to show the login page but need to click refresh after calling this SignOut method to do so, that is why I displayed the messagebox.
Hope this helps you.

Know if the user launched an app

Alright, this title might seem strange, but bear with me. I have an app which can be set on its preferences by the user to launch at login. That means I can expect sometimes the app will be launched by the user (clicking on the Dock/Finder, etc), but some other times the app will be launched automatically by the system, on login.
I would like to show a window when the app is launched by the user, but not when it is launched automatically (as I imagine that would be a pain for the user). How can I do that?
Although it may depend on how you intend to automate the launch of the app, you could use command line arguments to distinguish between system launch vs. user launch.
So, the command line launch might like like this:
MyApp -autoLaunch "Y"
To parse the command line args in a Cocoa app, you could use NSUserDefaults (Yes, you can!):
if( ![[NSUserDefaults standardUserDefaults] objectForKey:#"autoLaunch"] isEqualToString:"Y"] ) {
// do something for user initiated launch
}
I don't have an exact answer to your question. However, may I suggest that your app should show the window if the window was visible when the user last quit your app?
This may be more in-line with the Mac UI guidelines' suggestion on restoring apps and windows, and is within the user's expectations.
Also, a user who set your app to launch at login will probably understand to close the window and not have it restored the next time, or make the system also hide your app during login.