Skip to content

Example using iOS 11's SFAuthenticationSession to get cookies from Safari

Notifications You must be signed in to change notification settings

edenman/SFAuthenticationSession-example

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Use SFAuthenticationSession to get cookies from Safari

Example using iOS 11's SFAuthenticationSession to get cookies from Safari. Contains a simple python Flask web service to create and return cookies and an iOS app that uses SFAuthenticationSession API to fetch cookies from the Flask app. Assumes you have some level of familiarity with Xcode and the command line, but does not require experience with python / Flask.

Note: There appears to be a bug with SFAuthenticationSession that prevents this from working.

Running

You will need to start the Flask server, and run the iOS app in the simulator using xcode 9 (beta).

Run the Server

The following assume you have python 2.7 installed and set as your default python version:

cd server
pip install virtualenv
source env/bin/activate
pip install -r requirements.txt
python app.py

Go to http://0.0.0.0:5000/ in your browser to confirm the app is working. You should see something like the following:

Simple flask app to create and get cookies. Can redirect to a callbackUrl to deep link into app.

Example using cookie "user" - replace with any cookie of your choice:
/create-cookie/user - sets random cookie val for "user"
/get-cookie/user - gets cookie val for "user" with optional query param "callbackUrl" to be redirected to with cookie appended as query param
/delete-cookie/user - expires cookie for "user"

You can click around to test the endpoints. Navigating to /create-cookie/user creates a cookie for the key user, but you could use any key you want, for example /create-cookie/sessionID to create a random cookie value for the key sessionID.

Run the App

Xcode 9 and iOS 11 are required to run the app. To attempt fetching cookies from Safari, do the following:

  1. Run the app in a device simulator.
  2. From the simulator exit the app by pressing the home button and go to safari.
  3. Go to http://0.0.0.0:5000/create-cookie/user to create a cookie for the key "user".
  4. Go back to the app in the simulator and click the "Get cookie from Safari" button.
  5. You will see a dialogue like the following: SFAuthenticationSession dialogue screenshot
  6. Click continue; a SafariViewController will be launched and then you should be redirected back into your app with the cookie for "user" shown in the app.

About

Example using iOS 11's SFAuthenticationSession to get cookies from Safari

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 60.9%
  • Python 39.1%