Giter VIP home page Giter VIP logo

ohmyauth's Introduction

OhMyAuth

โš ๏ธ DEPRECATED, NO LONGER MAINTAINED

CI Status Version Carthage Compatible License Platform

Description

Simple OAuth2 library with a support of multiple services.

Usage

  • Setup:
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)
  • Safari app will be opened by default for authorization, if it's iOS9 and you'd like to use 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)
  • Show a login web page:
AuthContainer.serviceNamed("service")?.authorize()
  • Handle response. If you use 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!!!
      }
   }
}
  • Get an access token to include it in the each request. If token is about to expire it will be refreshed automagically, so you always get an active token is the completion closure:
AuthContainer.serviceNamed("service")?.accessToken(completion)
  • If you need to change user and have a separate URL for that:
AuthContainer.serviceNamed("service")?.changeUser()
  • If you don't have authorisation by code, but by username and password, there is a flow:
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!
}
  • If you need to get your tokens, expiry date, username, user UPN:
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)

Author

Hyper Interaktiv AS, [email protected]

Installation

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"

Author

Hyper Interaktiv AS, [email protected]

Contributing

We would love you to contribute to OhMyAuth, check the CONTRIBUTING file for more info.

License

OhMyAuth is available under the MIT license. See the LICENSE file for more info.

ohmyauth's People

Contributors

hyperseed avatar johnsundell avatar onmyway133 avatar ramongilabert avatar vadymmarkov avatar zenangst avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ohmyauth's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.