A ViewController for Instagram authentication.
Switch branches/tags
Nothing to show
Clone or download
Isuru Nanayakkara
Isuru Nanayakkara Make private properties public. Renamed delegate method.
Renamed InstagramAuthDelegate delegate method name to
Changed access control of clientId, clientSecret, redirectUri
properties from private to public so they can be set when used through
Updated README with more information on usage.
Latest commit 52c6776 Jun 3, 2016



A ViewController for Instagram authentication.

A UIViewController subclass that handles showing the Instagram login page, the authentication dance and finally returning the access token that can be used to communicate with the Instagram API afterwards.

Inspired by Instagram-Auth-iOS. Used PhotoBrowser as a stepping stone. I rewrote the login part in Swift, replced third-party library code with built-in Cocoa Touch frameworks and made it reusable.


  • iOS 8.0+
  • Xcode 7.3



  1. Download or clone the repo.
  2. Open the source folder.
  3. Add InstagramAuthViewController.swift to your project.
  4. Profit(?)!

Usage example

  • Go to Instagram's developer portal and register your application.
  • Take note of the client ID, client secret and redirect URI values.
let clientId = "<YOUR CLIENT ID>"
let clientSecret = "<YOUR CLIENT SECRET>"
let redirectUri = "<YOUR REDIRECT URI>"


  • Simply add the InstagramAuthViewController as the UIViewController's class in the Identity inspector.

let instagramAuthViewController = segue.destinationViewController as! InstagramAuthViewController
instagramAuthViewController.delegate = self
instagramAuthViewController.clientId = clientId
instagramAuthViewController.clientSecret = clientSecret
instagramAuthViewController.redirectUri = redirectUri


  • Initialize an instance of InstagramAuthViewController and present it like a normal ViewController.
let instagramAuthViewController = InstagramAuthViewController(clientId: clientId, clientSecret: clientSecret, redirectUri: redirectUri)
instagramAuthViewController.delegate = self
presentViewController(instagramAuthViewController, animated: true, completion: nil)
  • Either way, don't forget to implement the InstagramAuthDelegate.
func instagramAuthControllerDidFinish(accessToken: String?, error: NSError?) {
    if let error = error {
        print("Error logging in to Instagram: \(error.localizedDescription)")
    } else {
        print("Access token: \(accessToken!)")

Contribute & Bug Fixes

We would love for you to contribute to InstagramAuthViewController, check the LICENSE file for more info. Pull requests, bug fixes, improvements welcome.


Isuru Nanayakkara – @IJNanayakkaraisuru.nan@gmail.com

Distributed under the MIT license. See LICENSE for more information.