A simple library to make authenticating tvOS apps easy via their iOS counterparts.

Related tags

Apple TV Voucher
Overview

Voucher

The new Apple TV is amazing but the keyboard input leaves a lot to be desired. Instead of making your users type credentials into their TV, you can use Voucher to let them easily sign into the TV app using your iOS app.

How Does It Work?

Voucher uses Bonjour, which is a technology to discover other devices on your network, and what they can do. When active, Voucher on tvOS starts looking in your local network and over AWDL (Apple Wireless Direct Link) for any Voucher Server, on iOS.

Once it finds a Voucher Server, it asks it for authentication. Here's the demo app:

Sample tvOS App

The demo iOS app can then show a notification to the user (you can show whatever UI you want, or even no UI):

iOS app shows a dialog

If the user accepts, then the iOS app can send some authentication data back to the tvOS app (in this case, an auth token string)

Sample tvOS App

Installation

Voucher is available through Carthage and CocoaPods. You can also manually install it, if that's your jam.

Carthage

github "rsattar/Voucher"

CocoaPods

pod 'Voucher'

Manual

  • Clone the repo to your computer
  • Copy only the source files in Voucher subfolder over to your project

Using Voucher

In your tvOS app, when the user wants to authenticate, you should create a VoucherClient instance and start it:

tvOS (Requesting Auth)

When the user triggers a "Login" button, your app should display some UI instructing them to open their iOS App to finish logging in, and then start the voucher client, like below:

import Voucher

func startVoucherClient() {
    let uniqueId = "SomethingUnique";
    self.voucher = VoucherClient(uniqueSharedId: uniqueId)
    
    self.voucher.startSearchingWithCompletion { [unowned self] authData, displayName, error in

        // (authData is of type NSData)
        if authData != nil {
            // User granted permission on iOS app!
            self.authenticationSucceeded(authData!, from: displayName)
        } else {
            self.authenticationFailed()
        }
    }
}

iOS (Providing Auth)

If your iOS app has auth credentials, it should start a Voucher Server, so it can answer any requests for a login. I'd recommend starting the server when (and if) the user is logged in.

import Voucher

func startVoucherServer() {
    let uniqueId = "SomethingUnique"
    self.server = VoucherServer(uniqueSharedId: uniqueId)

    self.server.startAdvertisingWithRequestHandler { (displayName, responseHandler) -> Void in

        let alertController = UIAlertController(title: "Allow Auth?", message: "Allow \"\(displayName)\" access to your login?", preferredStyle: .Alert)
        alertController.addAction(UIAlertAction(title: "Not Now", style: .Cancel, handler: { action in
            responseHandler(nil, nil)
        }))

        alertController.addAction(UIAlertAction(title: "Allow", style: .Default, handler: { action in
            let authData = "THIS IS AN AUTH TOKEN".dataUsingEncoding(NSUTF8StringEncoding)!
            responseHandler(authData, nil)
        }))

        self.presentViewController(alertController, animated: true, completion: nil)
        
    }
}

Recommendations

Use tokens, not passwords

While you can send whatever data you like back to tvOS, you should you pass back an OAuth token, or better yet, generate some kind of a single-use token on your server and send that. Cluster, for example, uses single-use tokens to do auto-login from web to iOS app. Check out this Medium post that shows how I do it! The same model can apply for iOS to tvOS logins.

Voucher can't be the only login option

In your login screen, you must still show the manual entry UI according to the App Store Submission Guidelines (Section 2.27). Add messaging that, in addition to the on screen form, the user can simply open the iOS app to login.

Todo / Things I'd Love Your Help With!

  • Encryption? Currently Voucher does not encrypt any data between the server and the client, so I suppose if someone wanted your credentials (See Recommendations section above), they could have a packet sniffer on your local network and access your credentials.

  • Make Voucher Server work on OS X, and even tvOS! Would probably just need new framework targets, and additional test apps.

Further Reading

Check out Benny Wong's post on why Apple TV sign in sucks. He also has a demo tvOS Authing project, which you should check out!

Requirements

  • iOS 7.0 and above
  • tvOS 9.0
  • Xcode 8

License

Voucher is available using an MIT license. See the LICENSE file for more info.

I'd Love to Know If You're Using Voucher!

Post to this Github "issue" I made to help us track who's using Voucher 👍

Comments
  • Not working in real device.

    Not working in real device.

    Hi, probably this isn't a library issue. I'm implementing this library and works like a charm with any iOS device as a server and Apple TV Simulator, but when I run it on a real Apple TV, the client doesn't find the server. Am I missing something? Like a said, it works perfectly with TV Simulator but not on a real device.

    Thanks!

    opened by FernandoReynoso 1
  • Correct the spelling of CocoaPods in README

    Correct the spelling of CocoaPods in README

    This pull requests corrects the spelling of CocoaPods 🤓 https://github.com/CocoaPods/shared_resources/tree/master/media

    Created with cocoapods-readme.

    opened by ReadmeCritic 0
  • Not getting authorization request in IOS device immediately

    Not getting authorization request in IOS device immediately

    I'm running this code of both the tvos and ios app in the simulator. In logs of the tvos app its showing this error NSStreamErrorOccurred (fallthrough)

    And after one minute i'm getting Authrization request in IOS device.

    am i missing something ?

    2020-01-25 12:28:18.180661+0530 Voucher tvOS App[68664:767659] Browser will search 2020-01-25 12:28:25.085173+0530 Voucher tvOS App[68664:767659] Browser found service: iPhone 11 Pro Max, more coming: NO 2020-01-25 12:29:40.464556+0530 Voucher tvOS App[68664:778604] [] nw_socket_handle_socket_event [C5.1.1:1] Socket SO_ERROR [60: Operation timed out] 2020-01-25 12:29:40.466096+0530 Voucher tvOS App[68664:779648] [] nw_connection_get_connected_socket [C5] Client called nw_connection_get_connected_socket on unconnected nw_connection 2020-01-25 12:29:40.466587+0530 Voucher tvOS App[68664:779648] TCP Conn 0x6000010eda40 Failed : error 0:60 [60] 2020-01-25 12:29:40.466913+0530 Voucher tvOS App[68664:767659] NSStreamErrorOccurred (fallthrough) 2020-01-25 12:29:40.467225+0530 Voucher tvOS App[68664:767659] NSStreamEventEndEncountered 2020-01-25 12:29:40.467374+0530 Voucher tvOS App[68664:767659] => Input Stream 2020-01-25 12:30:56.072708+0530 Voucher tvOS App[68664:779650] [] nw_socket_handle_socket_event [C6.1.1:1] Socket SO_ERROR [60: Operation timed out] 2020-01-25 12:30:56.073919+0530 Voucher tvOS App[68664:780808] [] nw_connection_get_connected_socket [C6] Client called nw_connection_get_connected_socket on unconnected nw_connection 2020-01-25 12:30:56.074235+0530 Voucher tvOS App[68664:780808] TCP Conn 0x6000010e1080 Failed : error 0:60 [60] 2020-01-25 12:30:56.074448+0530 Voucher tvOS App[68664:767659] NSStreamErrorOccurred (fallthrough) 2020-01-25 12:30:56.074604+0530 Voucher tvOS App[68664:767659] NSStreamEventEndEncountered 2020-01-25 12:30:56.074772+0530 Voucher tvOS App[68664:767659] => Input Stream 2020-01-25 12:30:56.310391+0530 Voucher tvOS App[68664:767659] Input stream open 2020-01-25 12:30:56.310522+0530 Voucher tvOS App[68664:767659] Output stream open 2020-01-25 12:30:56.310635+0530 Voucher tvOS App[68664:767659] Output stream has space available 2020-01-25 12:30:56.310846+0530 Voucher tvOS App[68664:767659] Sent 295 bytes 2020-01-25 12:30:56.310947+0530 Voucher tvOS App[68664:767659] Finished sending whole data buffer 2020-01-25 12:30:56.311054+0530 Voucher tvOS App[68664:767659] Output stream has space available

    opened by bc1213 0
  • Voucher Server stopped publishing, due to error: -72004

    Voucher Server stopped publishing, due to error: -72004

    Voucher Server stopped publishing, due to error: -72004

    This seems related to the uniqueSharedId that is provided to either the client or server. I tested this with different IDs and had these results:

    weoripuwieur;uqwer: Error. weoripuwieuruqwer: Works.

    This error seems to be caused by provided 'special' characters in the unique ID field. The server will not launch and will produce this error code, plus the client will also not launch and will produce this error code in a different way. Could this be confirmed?

    opened by SirArkimedes 0
  • Feature request: Using Symmetric-key algorithm AES? to protect data transfer?

    Feature request: Using Symmetric-key algorithm AES? to protect data transfer?

    Using Symmetric-key algorithm AES (or something like that) to protect data transfer if the TV & iPhone communicated via open wifi ?

    the key can show (via text/QR?) on TV Screen (random generated, or encrypt the key again in code) or just embed the key in code...

    opened by ryh 4
  • Post here if you use Voucher for your app!

    Post here if you use Voucher for your app!

    It would be really cool to know if you're using Voucher, so post in here what your project or app is, with a link!

    Screenshots would be awesome too, to see how you've built the auth process! :+1:

    help wanted 
    opened by rsattar 5
Owner
Riz
Riz
YouTube video player for iOS, tvOS and macOS

About XCDYouTubeKit is a YouTube video player for iOS, tvOS and macOS. Are you enjoying XCDYouTubeKit? You can say thank you with a tweet. I am also a

Cédric Luthi 2.9k Dec 21, 2022
tvOS controls and extensions that add parallax effect to your application.

ParallaxView Summary Easy to use UIView, UICollectionViewCell with parallax effect and extensions to add this effect to any UIView. Rotate view using

PGS Software 466 Nov 13, 2022
Light and scrollable view controller for tvOS to present blocks of text

TvOSTextViewer Light and scrollable view controller for tvOS to present blocks of text Description TvOSTextViewer is a view controller to present bloc

David Cordero 45 Oct 27, 2022
Light wrapper of UIButton that allows extra customization for tvOS

FocusTvButton Light wrapper of UIButton that allows extra customization for tvOS If you would like to have the same level of customization in tablevie

David Cordero 68 Nov 12, 2022
📺 A tvOS button which truncates long text with '... More'.

TvOSMoreButton ?? A tvOS button which truncates long text with '... More'. The TvOSMoreButton is a simple view which aims to mirror the behavior of Ap

Chris Goldsby 56 Oct 27, 2022
PIN keyboard for tvOS

TvOSPinKeyboard PIN keyboard for tvOS Description TvOSPinKeyboard is a view controller that allows easily asking for PIN codes in tvOS. Requirements t

Zattoo 102 Oct 5, 2022
Light wrapper of UITableViewCell that allows extra customization for tvOS

TvOSCustomizableTableViewCell Light wrapper of UITableViewCell that allows extra customization for tvOS If you would like to have the same level of cu

Zattoo 31 Nov 9, 2022
TvOSSlider is an implementation of UISlider for tvOS.

TvOSSlider TvOSSlider is an implementation of UISlider for tvOS. Description and usage TvOSSlider palliates missing an implementation of UISlider for

Zattoo 36 Dec 12, 2022
A simple library to make authenticating tvOS apps easy via their iOS counterparts.

Voucher The new Apple TV is amazing but the keyboard input leaves a lot to be desired. Instead of making your users type credentials into their TV, yo

Riz 516 Nov 24, 2022
A simple to use, standard interface for authenticating to oauth 2.0 protected endpoints via SFSafariViewController.

AuthenticationViewController A simple to use, standard interface for authenticating to OAuth 2.0 protected endpoints via SFSafariViewController. Instr

Raul Riera 256 Dec 14, 2022
This app is a sample app that recognizes specific voice commands such as "make it red", "make it blue", "make it green", and "make it black" and change the background color of the view in the frame.

VoiceOperationSample This app is a sample app that recognizes specific voice commands such as "make it red", "make it blue", "make it green", and "mak

Takuya Aso 3 Dec 3, 2021
SpotifyLogin is a Swift 5 Framework for authenticating with the Spotify API.

SpotifyLogin SpotifyLogin is a Swift 5 Framework for authenticating with the Spotify API. Usage of this framework is bound under the Developer Terms o

Spotify 343 Dec 8, 2022
AnylineFaceAuthentication pairs identity document scanning with a real-time liveness check utilizing the iPhone's camera, best suited for authenticating users over the internet.

AnylineFaceAuthentication AnylineFaceAuthentication pairs identity document scanning with a real-time liveness check utilizing the iPhone's camera, be

null 0 Mar 7, 2022
Swift framework for authenticating with the Spotify API

SpotifyLogin SpotifyLogin is a Swift 5 Framework for authenticating with the Spotify API. Usage of this framework is bound under the Developer Terms o

Spotify 344 Jan 4, 2023
ToDoList - An ios app that help users to set their todos and make it easy to remember this todos

An ios app that help users to set their todos and make it easy to remember this todos by reminders them when todo time's up, this app make sure that you don't forget any todos that you want to do just give it to the app and let the app hundle it for you.

Ahmed Mahrous 1 Apr 25, 2022
Provides an iOS view controller allowing a user to draw their signature with their finger in a realistic style.

Swift version now available! Mimicking pen-on-paper signatures with a touch screen presents a difficult set of challenges. The rate touch events are e

Uber Open Source 1.3k Jan 6, 2023
Allows users to pull in new song releases from their favorite artists and provides users with important metrics like their top tracks, top artists, and recently played tracks, queryable by time range.

Spotify Radar Spotify Radar is an iOS application that allows users to pull in new song releases from their favorite artists and provides users with i

Kevin Li 630 Dec 13, 2022
SharedImages Screen grabs Main Features Private & self-owned social media Users store their images in their own cloud storage (Dropbox or Google Drive

SharedImages Screen grabs Main Features Private & self-owned social media Users store their images in their own cloud storage (Dropbox or Google Drive

Christopher Prince 12 Feb 10, 2022
Camera and Microphone streaming library via RTMP, HLS for iOS, macOS, tvOS.

HaishinKit (formerly lf) Camera and Microphone streaming library via RTMP, HLS for iOS, macOS, tvOS. Issuesの言語は、日本語が分かる方は日本語でお願いします! Sponsored with ??

shogo4405 2.4k Dec 29, 2022
Camera and Microphone streaming library via RTMP, HLS for iOS, macOS, tvOS.

HaishinKit Camera and Microphone streaming library via RTMP, HLS for iOS, macOS, tvOS. Issuesの言語は、日本語が分かる方は日本語でお願いします! Sponsored with ?? by Enterprise

shogo4405 2.4k Jan 2, 2023