0

Goal
I am trying to load Sharepoint site pages in Xamarin WebView with URL like SharePoint Android/iOS app showing sitepages without asking user to log in at webview.

Progress
The app uses ADAL's AcquireTokenAsync() to get the access token from Azure AD and set the WebView source as SharePoint modern site pages URL. As the user first-time signs in to the app with AcquireTokenAsync(), the webview is load site page successfully.

Issue:
After the user closes and relaunches the app, it uses AcquireTokenSilentAsync() to authenticate. But when the webview loading the site page with URL, Microsoft ask the user to log in again at webview.

Notes
After authentication with AcquireTokenSilentAsync(), there are some cookies missing in CookieManager and NSHttpCookieStorage. I also tried with MSAL and the issue still persist.

Question
Why there are cookies missing when the app using AcquireTokenSilentAsync(). How can achieve the goal without asking user to log in twice?

Here is some snapshot of code for authentication and webview.

var platformParams = new PlatformParameters((Activity)Forms.Context);
try
{
authResult = await authContext.AcquireTokenSilentAsync(resource, clientId);
}
catch (Exception)
{
authResult = await authContext.AcquireTokenAsync(resource, clientId, uri, platformParams);
}

var sitePageWebView = new WebView
{
Source = "https://company.sharepoint.com/SitePages/page-title.aspx",
MinimumHeightRequest = 1000,
HorizontalOptions = LayoutOptions.FillAndExpand
};

Sam Huang
  • 3
  • 2
  • ,**After authentication with AcquireTokenSilentAsync(), there are some cookies missing in CookieManager and NSHttpCookieStorage.**, about CookieManager doesn't store all cookies, I find one thread that you can take a look:https://stackoverflow.com/questions/52518355/xamarin-android-cookiemanager-doesnt-store-all-cookies, I also find one article [How to display a SharePoint page in an iOS mobile app with Xamarin, WebView control and NTLM authentication](https://collab365.community/display-sharepoint-page-ios-mobile-app-xamarin-webview-control-ntlm-authentication/) – Cherry Bu - MSFT Jan 30 '20 at 04:30
  • Thank for response @CherryBu-MSFT, I will have a look first one. But the second one is using user credential for SharePoint on-premise, I don's know user credential because the app using ADAL and the challenge is for Sharepoint online. – Sam Huang Jan 31 '20 at 00:36
  • We are trying to achieve something similar, did you get it resolved? – Ahmed Masud Jul 17 '22 at 00:15

0 Answers0