All Projects → mackuba → Safariautologintest

mackuba / Safariautologintest

A demo showing how you can auto-login users to an iOS app using SafariViewController (on iOS 9) and SFAuthenticationSession (on iOS 11)

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Safariautologintest

Stay
Stay is a local userscript manager and an extension sample for Safari on iOS/iPadOS.
Stars: ✭ 672 (+40%)
Mutual labels:  safari, ios-app
ANODA-Turn-Timer
ANODA Open Source iOS Swift example app
Stars: ✭ 19 (-96.04%)
Mutual labels:  ios-app, ios11
Augmentedsolarsystem
An Augmented reality experience to explore planets in our Solar System
Stars: ✭ 69 (-85.62%)
Mutual labels:  ios-app, ios11
MoviezApp
Simple iOS application that provides you with the latest movies in cinema.
Stars: ✭ 22 (-95.42%)
Mutual labels:  ios-app, ios11
Messenger
Open source, native iOS Messenger, with realtime chat conversations (full offline support).
Stars: ✭ 4,264 (+788.33%)
Mutual labels:  ios-app
Ios Tagent
iOS support agent for automation
Stars: ✭ 400 (-16.67%)
Mutual labels:  ios-app
Easynavigation
一款超级简单的导航条管理工具。完全自定义导航条。没有UINavigationBar 和 UINavigationItem 这两个类。完全是对UIView的操作。
Stars: ✭ 393 (-18.12%)
Mutual labels:  ios11
Httper Ios
App for developers to test REST API.
Stars: ✭ 376 (-21.67%)
Mutual labels:  ios-app
Facecropper
✂️ Crop faces, inside of your image, with iOS 11 Vision api.
Stars: ✭ 479 (-0.21%)
Mutual labels:  ios11
Example Ios Apps
 A curated list of Open Source example iOS apps developed in Swift. An amazing list for people who are beginners and learning ios development and for ios developers who need any example app or feature.
Stars: ✭ 461 (-3.96%)
Mutual labels:  ios-app
Material Kit React Native
Material Kit React Native
Stars: ✭ 424 (-11.67%)
Mutual labels:  ios-app
Githubcontributionsios
Show off your GitHub contributions from your lock screen 📱
Stars: ✭ 410 (-14.58%)
Mutual labels:  ios-app
Pwa Bugs
🚔 List of PWA Bugs and workarounds
Stars: ✭ 444 (-7.5%)
Mutual labels:  safari
Autoinch
优雅的iPhone全尺寸/等比例精准适配工具
Stars: ✭ 395 (-17.71%)
Mutual labels:  ios-app
Browsertime
Your browser, your page, your scripts!
Stars: ✭ 474 (-1.25%)
Mutual labels:  safari
Polyglot
🌏 The missing Safari extension that translates selected text into your native language.
Stars: ✭ 387 (-19.37%)
Mutual labels:  safari
Cards
Awesome iOS 11 appstore cards in swift 5.
Stars: ✭ 4,017 (+736.88%)
Mutual labels:  ios11
React Native Mixpanel
A React Native wrapper for Mixpanel tracking
Stars: ✭ 451 (-6.04%)
Mutual labels:  ios-app
Ios 11.1.2 15b202 Jailbreak
iOS 11.1.2 (15B202) Jailbreak
Stars: ✭ 413 (-13.96%)
Mutual labels:  ios11
Bangumi
💫 An unofficial bgm.tv app client for Android and iOS, built with React Native. 类似专门做ACG的豆瓣, 已适配 iOS/Android, mobile/Pad, light/dark theme, 并加入了很多独有的增强功能
Stars: ✭ 409 (-14.79%)
Mutual labels:  ios-app

Safari auto-login (iOS 9)

This demo shows how you can automatically log in users to your iOS app after they install it based on cookies previously set in Safari. The idea is that if you have a way of logging them in somewhere in the browser before they download your app, or they have previously logged in to your webapp before installing it, you can automatically recognize them without them having to go through an in-app login flow and enter the same login info again.

This project was inspired by this article by LaunchKit.

== UPDATE 2017 ==

The original approach doesn't work anymore - some people of course had to use it for evil purposes (surprise surprise) and Apple has changed a few things:

  • the App Store Review Guidelines (5.1.1) now specifically say that:

    SafariViewContoller must be used to visibly present information to users; the controller may not be hidden or obscured by other views or layers. Additionally, an app may not use SafariViewController to track users without their knowledge and consent.

  • since iOS 10, SafariViewController doesn't seem to load at all when alpha is set to 0

  • since iOS 11, SafariViewController uses a separate cookie storage from Safari, so even if you manage to make it load, it won't recognize you

Possible alternatives:

  • Shared Web Credentials (if the user uses iCloud Keychain)
  • SFAuthenticationSession, a new API added in iOS 11 beta 3 (also supports e.g. 1Password, but loses some of the "magic" of automatically recognizing the user)
  • one popular third party service that uses fingerprinting and other shady techniques, but please don't use that 🙏

I've added support for SFAuthenticationSession in the app - you can launch it by tapping the "Authenticate" button. It's actually pretty nice and the result is very similar to the old approach, except you get a popup first where you have to confirm access and then you see the SVC slide up and down.

See it in action

Here's how it looks:

video

How it's done

It's actually pretty simple:

  • the app creates an SFSafariViewController at startup and tells it to load a special page in your webapp that automatically redirects back to your app using a custom URL scheme (you can only pass something back to your app with a redirect, since the app has no direct access to the contents of the Safari View Controller)
  • the main view controller presents the Safari View Controller as a popup (it needs to be displayed to start loading the page), but to hide the Safari View Controller from the user, it sets its modalPresentationStyle to .OverCurrentContext and its view's alpha to 0
  • the page reads the name from the previously set cookie and redirects to svclogintest://name/yournamehere; that triggers the callback application(handleOpenURL:) in the application delegate, which notifies the view controller about it through an NSNotification
    • you could also use universal app links for this, which would avoid a possible issue with some other app using the same URL scheme as yours, accidentally or on purpose
  • when the page finishes loading, the view controller automatically cleans up the SVC
  • when the view controller receives the notification from the delegate, it updates the label in the center with the user's name

So this way you can remember the user between app installations and even before it's installed for the first time, as long as you control the site which sets the cookies and can make it redirect to the custom URL, and as long as the user doesn't clear the cookies in Safari. (I've seen an issue though where even after clearing the cookies the SVC was still seeing them, even though Safari didn't - might be a bug in the beta?)

For the new 2017 version using SFAuthenticationSession:

  • the app creates an SFAuthenticationSession and saves it in an instance variable (otherwise the popup disappears immediately)
  • it tells is to load exactly the same URL as in SVC and launches it by calling start()
    • anyone knows how to change the "(null)" in the message that's shown in the popup? or what the callbackURLScheme is for, since it seems to work just fine regardless what you put there?
  • if authentication succeeds, you get a URL which you can handle the same way as in application(handleOpenURL:), if not, you get an error object

How to test it

  • download or clone the project

  • in a terminal, go into the project's directory and start an HTTP server in that folder:

      python -m SimpleHTTPServer
    
  • open the project in Xcode 7

  • build & run

  • to log in & out, go to http://localhost:8000 in Safari in the simulator and use the form to update the name

Credits / license

Created by Kuba Suder, licensed under WTFPL license.

If you have any suggestions or comments, please let me know via Twitter @kuba_suder, email or GitHub issues.

Note: please don't use this for any evil purposes 🙏

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].