-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added support for VKontakte (aka VK.com)
- Loading branch information
Andrey Toropchin
committed
Jul 14, 2016
1 parent
aab7ff1
commit 7eace6f
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |