Skip to content

Commit

Permalink
added support for VKontakte (aka VK.com)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Toropchin committed Jul 14, 2016
1 parent aab7ff1 commit 7eace6f
Show file tree
Hide file tree
Showing 2 changed files with 46 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 @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
A132748C1D374C81002ED68B /* VKontakte.swift in Sources */ = {isa = PBXBuildFile; fileRef = A132748B1D374C81002ED68B /* VKontakte.swift */; };
DF74EC341CE2A8BB008F16BF /* Simplicity.h in Headers */ = {isa = PBXBuildFile; fileRef = DF74EC331CE2A8BB008F16BF /* Simplicity.h */; settings = {ATTRIBUTES = (Public, ); }; };
DF74EC3F1CE2A943008F16BF /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = DF74EC3E1CE2A943008F16BF /* LICENSE */; };
DF74EC411CE2AC2F008F16BF /* LoginProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF74EC401CE2AC2F008F16BF /* LoginProvider.swift */; };
Expand All @@ -22,6 +23,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
A132748B1D374C81002ED68B /* VKontakte.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VKontakte.swift; sourceTree = "<group>"; };
DF74EC301CE2A8BB008F16BF /* Simplicity.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Simplicity.framework; sourceTree = BUILT_PRODUCTS_DIR; };
DF74EC331CE2A8BB008F16BF /* Simplicity.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Simplicity.h; sourceTree = "<group>"; };
DF74EC351CE2A8BB008F16BF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -86,6 +88,7 @@
DF74EC491CE2ACF0008F16BF /* Facebook.swift */,
DFB389851CECFBFC001DDCCE /* Google.swift */,
DF8674F81D1A0351005C636A /* Instagram.swift */,
A132748B1D374C81002ED68B /* VKontakte.swift */,
);
name = LoginProviders;
sourceTree = "<group>";
Expand Down Expand Up @@ -194,6 +197,7 @@
buildActionMask = 2147483647;
files = (
DF74EC411CE2AC2F008F16BF /* LoginProvider.swift in Sources */,
A132748C1D374C81002ED68B /* VKontakte.swift in Sources */,
DFB389861CECFBFC001DDCCE /* Google.swift in Sources */,
DFB389881CED3667001DDCCE /* OAuth2.swift in Sources */,
DF74EC451CE2AC54008F16BF /* Helpers.swift in Sources */,
Expand Down
42 changes: 42 additions & 0 deletions Simplicity/VKontakte.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// VKontakte.swift
// Simplicity
//
// Created by Andrey Toropchin on 14.07.16.
// Copyright © 2016 Stormpath. All rights reserved.
//

/**
Class implementing VKontakte (VK.com) implicit grant flow.

## Using Instagram in your app.

To get started, you first need to [create an application](https://vk.com/dev/) with VKontakte.
After registering your app, go into your client settings page.
Set App Bundle ID for iOS to your App Bundle in Xcode -> Target -> Bundle Identifier (e.g. com.developer.applicationName)

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 `vk[CLIENT_ID_HERE]`. Then, you can initiate the login
screen by calling:
```
Simplicity.login(VKontakte()) { (accessToken, error) in
// Insert code here
}
```
*/

public class VKontakte: OAuth2 {

public init() {
guard let urlScheme = Helpers.registeredURLSchemes(filter: {$0.hasPrefix("vk")}).first,
range = urlScheme.rangeOfString("\\d+", options: .RegularExpressionSearch) else {
preconditionFailure("You must configure your VK URL Scheme to use VK login.")
}
let clientId = urlScheme.substringWithRange(range)
let authorizationEndpoint = NSURL(string: "https://oauth.vk.com/authorize")!
let redirectEndpoint = NSURL(string: urlScheme + "://authorize")!

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

0 comments on commit 7eace6f

Please sign in to comment.