---
title: "#132: Social Authentication with SimpleAuth 👥🔐"
url: https://littlebitesofcocoa.com/132-social-authentication-with-simpleauth
author: Jake Marsh
date: 2015-11-24
published: 2015-11-24
topics: ["Networking","Libraries"]
description: "Building a good authentication system is a lot of work. Instead of starting from scratch, it'd be great if we could build on top of some existing popular..."
---

# #132: Social Authentication with SimpleAuth 👥🔐

By Jake Marsh, November 24, 2015. HTML: https://littlebitesofcocoa.com/132-social-authentication-with-simpleauth

Building a good authentication system is a lot of work. Instead of starting from scratch, it'd be great if we could build on top of some existing popular service, and allow our users to log in with their existing account there. 

Today we'll check out [SimpleAuth][1] from [Caleb Davenport][2]. It provides an extremely easy-to-use way to implement social sign-in inside our **apps**. Let's take a look:

_SimpleAuth_ is built around the concept of **Providers**. In this context, a provider contains all the code needed to talk to individual services like **Twitter**, **Facebook**, etc.

Let's add support for signing in with **Twitter** to an app. We'll start by adding the pod to our `Podfile`, then run `pod install`.

``` ruby
pod 'SimpleAuth/Twitter'
```

Then, we'll need a consumer key and secret from **Twitter**. We can get these by [creating a new app][3] on **Twitter's** developer portal.

Back in our **Application Delegate**, we'll configure _SimpleAuth's_ **Twitter provider** with our info:

``` swift
SimpleAuth.configuration()["twitter"] = [
  "consumer_key": "12345REDACTED",
  "consumer_secret": "ABCDETOPSECRET"
]
```

Finally, we can sign a user in like this:

``` swift
SimpleAuth.authorize("twitter") { userDictionary, error in
  User(username: userDictionary["nickname"]).persist()
}
```

Then we can grab their **Twitter** username out of a user dictionary. (Which contains keys like `uid`, `image`, etc.) _SimpleAuth_ uses these names to abstract away the different attribute names each service uses to represent these values. For example, the field `uid` always holds a unique user identifier and is present on almost all **providers**.

_SimpleAuth_ ships with a <i>ton</i> of built-in **providers** (Twitter, Facebook, Instagram, Tumblr, Dropbox, Foursquare, etc.). It also makes it very straightforward to create our own **providers**, just in case we ever need to. Neat!

More info about _SimpleAuth_ can be found at [git.io/simpleauth][1].

[1]: http://git.io/simpleauth
[2]: https://github.com/calebd
[3]: https://apps.twitter.com/app/new
