Skip to content

Commit

Permalink
added instagram, although their API is having issues with custom url …
Browse files Browse the repository at this point in the history
…schemes. fingers crossed it's not intentional
  • Loading branch information
edjiang committed Jun 23, 2016
1 parent c8901b7 commit ad558ea
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Simplicity.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
DF74EC471CE2AC6F008F16BF /* Simplicity.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF74EC461CE2AC6F008F16BF /* Simplicity.swift */; };
DF74EC4A1CE2ACF0008F16BF /* Facebook.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF74EC491CE2ACF0008F16BF /* Facebook.swift */; };
DF74EC4C1CE2AD19008F16BF /* Simplicity.podspec in Resources */ = {isa = PBXBuildFile; fileRef = DF74EC4B1CE2AD19008F16BF /* Simplicity.podspec */; };
DF8674F91D1A0351005C636A /* Instagram.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF8674F81D1A0351005C636A /* Instagram.swift */; };
DFB3897F1CEBAA57001DDCCE /* LoginError.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFB3897E1CEBAA57001DDCCE /* LoginError.swift */; };
DFB389811CEBAA98001DDCCE /* OAuth2Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFB389801CEBAA98001DDCCE /* OAuth2Error.swift */; };
DFB389861CECFBFC001DDCCE /* Google.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFB389851CECFBFC001DDCCE /* Google.swift */; };
Expand All @@ -32,6 +33,7 @@
DF74EC461CE2AC6F008F16BF /* Simplicity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Simplicity.swift; sourceTree = "<group>"; };
DF74EC491CE2ACF0008F16BF /* Facebook.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Facebook.swift; path = LoginProviders/Facebook.swift; sourceTree = "<group>"; };
DF74EC4B1CE2AD19008F16BF /* Simplicity.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Simplicity.podspec; sourceTree = "<group>"; };
DF8674F81D1A0351005C636A /* Instagram.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Instagram.swift; path = LoginProviders/Instagram.swift; sourceTree = "<group>"; };
DFB3897E1CEBAA57001DDCCE /* LoginError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoginError.swift; sourceTree = "<group>"; };
DFB389801CEBAA98001DDCCE /* OAuth2Error.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OAuth2Error.swift; sourceTree = "<group>"; };
DFB389851CECFBFC001DDCCE /* Google.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Google.swift; path = LoginProviders/Google.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -83,6 +85,7 @@
children = (
DF74EC491CE2ACF0008F16BF /* Facebook.swift */,
DFB389851CECFBFC001DDCCE /* Google.swift */,
DF8674F81D1A0351005C636A /* Instagram.swift */,
);
name = LoginProviders;
sourceTree = "<group>";
Expand Down Expand Up @@ -197,6 +200,7 @@
DF74EC4A1CE2ACF0008F16BF /* Facebook.swift in Sources */,
DFB389811CEBAA98001DDCCE /* OAuth2Error.swift in Sources */,
DFB3897F1CEBAA57001DDCCE /* LoginError.swift in Sources */,
DF8674F91D1A0351005C636A /* Instagram.swift in Sources */,
DF74EC471CE2AC6F008F16BF /* Simplicity.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
46 changes: 46 additions & 0 deletions Simplicity/LoginProviders/Instagram.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// Instagram.swift
// Simplicity
//
// Created by Edward Jiang on 6/21/16.
// Copyright © 2016 Stormpath. All rights reserved.
//

import UIKit

/**
Class implementing Instagram's implicit grant flow.

## Using Instagram in your app.

To get started, you first need to [register an
application](https://www.instagram.com/developer/) with
Instagram. After registering your app, go into your client settings page. Under
the security tab, add `instagram[CLIENT_ID_HERE]://authorize` as a valid
redirect URI, replacing `[APP_ID_HERE]` with your Instagram Client ID.

Finally, open up your App's Xcode project and go to the project's
info tab. Under "URL Types", add a new entry, and in the URL schemes form
field, type in `instagram[CLIENT_ID_HERE]`. Then, you can initiate the login
screen by calling:
```
Simplicity.login(Instagram()) { (accessToken, error) in
// Insert code here
}
```
*/
public class Instagram: OAuth2 {
public init() {
guard let urlScheme = Helpers.registeredURLSchemes(filter: {$0.hasPrefix("instagram")}).first else {
preconditionFailure("You must configure your Instagram URL Scheme to use Instagram login.")
}
let clientId = urlScheme.substringFromIndex(urlScheme.startIndex.advancedBy(9))

let authorizationEndpoint = NSURL(string: "https://api.instagram.com/oauth/authorize/")!
let redirectEndpoint = NSURL(string: urlScheme + "://authorize")!

super.init(clientId: clientId, authorizationEndpoint: authorizationEndpoint, redirectEndpoint: redirectEndpoint, grantType: .Implicit)

self.scopes = ["basic"]
}
}

0 comments on commit ad558ea

Please sign in to comment.