:closed_lock_with_key: Simple OAuth2 library with a support of multiple services.
⚠️ DEPRECATED, NO LONGER MAINTAINED
Simple OAuth2
library with a support of multiple services.
let config = AuthConfig(
clientId: "client-id",
accessTokenUrl: NSURL(string: "access-token-url")!,
accessGrantType: "authorization_code",
authorizeURL: NSURL(string: "authorise-url")!,
changeUserURL: NSURL(string: "change-user-url")!,
redirectURI: "yourapp://auth")
config.extraAccessTokenParameters = ["resource": "resource"]
config.extraRefreshTokenParameters = ["resource": "resource"]
let service = AuthService(name: "service", config: config)
AuthContainer.addService(service)
SFSafariViewController
, there is a ready-to-use class for you:// SFSafariViewController will be presented on top of provided controller
service.config.webView = SafariWebView(viewController: viewController)
AuthContainer.serviceNamed("service")?.authorize()
SafariWebView
it will be dismissed automagically:func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
AuthContainer.serviceNamed("service")?.accessToken(URL: url) { accessToken, error in
if let accessToken = accessToken where error == nil {
// User is logged in!!!
}
}
}
AuthContainer.serviceNamed("service")?.accessToken(completion)
AuthContainer.serviceNamed("service")?.changeUser()
let config = AuthConfig(
clientId: "client-id",
accessTokenUrl: NSURL(string: "access-token-url")!,
accessGrantType: "password")
let service = AuthService(name: "service", config: config)
AuthContainer.addService(service)
let parameters = ["username": "weirdo", "password": "123456"]
service.accessToken(parameters: parameters) { accessToken, error in
// Ready!
}
let accessToken = AuthContainer.serviceNamed("service")?.locker.accessToken
let userUPN = AuthContainer.serviceNamed("service")?.locker.userUPN
And yeah, you could add as many auth services as you want if you have some
crazy setup in the app. Just register a new one with a different name:
let service = AuthService(name: "another-service", config: config)
Hyper Interaktiv AS, [email protected]
OhMyAuth is available through CocoaPods. To install
it, simply add the following line to your Podfile:
pod 'OhMyAuth'
OhMyAuth is also available through Carthage.
To install just write into your Cartfile:
github "hyperoslo/OhMyAuth"
Hyper Interaktiv AS, [email protected]
We would love you to contribute to OhMyAuth, check the CONTRIBUTING file for more info.
OhMyAuth is available under the MIT license. See the LICENSE file for more info.