How to pass auth from iOS native app to web app? - ios

I have my iOS app and my web app. Say I have n authenticated user in my iOS app and now I want to open a specific page of my web app for this user in a web view.
What is a good practice of doing so? Do I have to implement a special web page that would do the auth check and redirect to the page needed or is there a way to do this just via WKWebView?
Any kind of help is highly appreciated.

Related

React Native MSAL - SSO does not work from Native to Web - iOS

We are developing two new react native apps, and need to integrate Azure AD authentication at both the places. We also have existing web apps that are Azure AD enabled and the user can open the web links from our (new) native apps.
We have decided to use MSAL library (react-native-msal) to implement the authentication part mainly to support SSO between the native apps + the web apps that we open in the Safari browser.
We have followed all the steps that the react-native-msal library suggests and are able to achieve SSO between the two native apps.
However, when I login to one native app, and try to open the web app link using react linking, the web app prompts for the login credentials.
Note:
For authenticating user through native app, we are using "Authentication Session" with "prefersEphemeralWebBrowserSession = false" which ideally should share the SSO cookies with the Safari browser.
But clearly, this does not seem to work.
I would like to get some understanding on this problem and find out if others are facing this issue too? or is it just us?
In this case you need a preferred user token and send it along with the login request. For capturing the details of the user at the same time I suggest storing the details in the domain wide cookies that is known for all applications.
// Store the user details after login
document.cookie = "msal_details=Paul#xyz-corp.com;domain=.xyz-corp.com;path=/"
// use the user details
var user = getCookieByName("msal_username"); 
  userAgentApplication.loginRedirect(scopes, "&login_hint=" + user);
Lastly, you would need to implement this in your application.
Well, it turns out to be a problem with the simulator. This functionality works only on the physical devices (iPhone/iPad) and not on the simulators.
This should have been documented in the react-native-msal's document though.

Is it possible to share a session between web and iOS app?

I'm using AppAuth in my iOS app for Authorization. Specifically i'm using the Authorization Code flow.
Now with help of URL schema, I will open up iOS app when user clicks on a certain link on the web application. Ideally I would like to authenticate the user automatically from web to the iOS app after the user clicks on the link.
Is this possible?
The current Authorization Flow uses OIDExternalUserAgentSession

AspNet Owin Cookie authentication from mobile web view

I am working on a MVC web app that requires authentication(Cookie) and a web api that uses token based authentication(Bearer). I also have an IOS app that communicates with the Web Api. So far everything is working fine.
Now I have to implement a new functionality on the IOS app that basically needs to show a web view and load a specific part of the web app, but that page requires authentication. The user was previously already authenticated on the IOS app, so what can I do to avoid that the user has to authenticate twice, one for the Ios app and also in the web view?
Please advice,
Thanks.
This is the solution:
If you set the Authorization header in the same way we do it for Web Api requests (Bearer + Token) then it works. It seems that the Mvc.Authorize attribute not only check for the cookie but also for the token(in the same way the Http.Authorize does it).

Is it possible to call native ios Facebook login dialog from just a web page (not a web app)?

We have an ios app that uses native Facebook login just fine.
Then we also have a website (app is basically an optimized client for it) where people can login via Facebook too. When they open our website in mobile safari, they are directed to Facebook pages to authenticate there and it works, but.. it is still far from native and users have to retype credentials they often have in ios already.
So could it be possible to to somehow launch system fb authentication for just a web page (maybe using some clever URL schema?) and get granted token back to web?
Difficult way
As described here http://aaronparecki.com/articles/2012/07/29/1/oauth2-simplified#mobile-apps you could find URL scheme to trigger the native iOS app for app authorization:
fbauth://authorize?redirect_uri=[redirect_uri]&client_id=[client_id]&response_type=token
But if you call that link it's not possible to have a redirection. You could try to hack that redirection but maybe you could not find a way out.
A secure way to solve that problem is to use a SSO token to authenticate user on your App when he logs in, and next on Safari take a redirection, with a custom url to your APP, that do as bridge to FB App via Token stored in your APP. After FB authentication you can directly redirect user back to your landing page in Safari. As said by #Lego it's an alternative way to direct authenticate that could be made by going deep to custom URL used by FB.
No, it is not yet possible to directly authenticate the user via the native Facebook App, but it's possible to authenticate the user using a custom URL scheme which opens your native iOS app which then handles the authentication flow:
The user authenticates natively with your iOS App. You then store the user login (not password) in your app (i.e. using NSUserDefaults).
Then the user opens your web page in Mobile Safari. You redirect the user via a custom url scheme to your app (i.e. using myapp://authenticate). Apple documentation on implementing custom URL schemes: click
Now, if you have an active FB session in your iOS app, you can either directly redirect the user back to your landing page in Mobile Safari, passing the access token via url get parameter or you first re-authenticate the user, displaying a login view with the user name pre-filled, which you have stored in your iOS app before (step 1) and then redirect the user to your landing page, again all depending on session state and your security needs.
For opening face book app you can use Custom URL scheme. But i am not sure if u can authenticate user from it. In case if you could also then it will be confined up to the fb account which is already configured on that device app .so better try to use face book api or something
I don't get your question exactly but i think as per your question you want to create fb app Login in safari or in your custom web view.
is this perfect ?
as per my knowledge web view is different thing and native app is different thing.
if you are Login in web view then no need to check anything token or other thing because it will give you Logout thing there.
but if you are Login in your application then "developer.facebook.com" will definitely help you.
and yes, you will do most of the thing in your app as native facebook app do.
Hope it help....

Cookie managment in the blackberry mobile application

I have to implement the remember me functionality on my blackberry application so that to remember the user's login credentials for the next login. Could any one please guide me on this and tell me how can I accomplish this functionality and how to use cookie for this? I am developing my application in blackberry 5.0.
Thanks
Assuming it's really an application and not a website, just save your login token (that you get back from your web service) to the persistent store.

Resources