Coder Social home page Coder Social logo

oauth2.0-scala's Introduction

OAuth2.0 scala

This library provides the necessary tools to implement an OAuth 2.0 server. It is based on RFC 6749.

Getting Started

This project is using scala 2.11.8. To get started with SBT, add the following to your build.sbt file:

resolvers += "bintray algd" at "http://dl.bintray.com/content/algd/maven"

In case you want to use the akka-http module add the following. It is using akka 2.4.4.

libraryDependencies += "io.github.algd" %% "oauth2-scala-akka-http" % "0.4.0"

Otherwise only add:

libraryDependencies += "io.github.algd" %% "oauth2-scala-core" % "0.4.0"

Authorize endpoint

After creating a class that extends DataManager, you can instantiate an OAuth authorizer enabling the flows you are interested in:

val myDataManager: DataManager[MyUser] = new MyDataManager

val authorizer = new BaseAuthorizer(myDataManager) +
                 new ImplicitAuthorizer +
                 new CodeAuthorizer

val params = Map("some_oauth_param" -> "value")
                
val response = authorizer(user, params)

This even allows you to create your custom authorizers. The response of an authorizer will be a Future[UriResponse] containing a validation error or a successful response ready to be converted to a redirection uri.

Token endpoint

After creating a class that extends DataManager, you can instantiate an OAuth token granter enabling the flows you are interested in:

val myDataManager: DataManager[MyUser] = new MyDataManager

val granter = new BaseGranter(myDataManager) +
              new AuthorizationCodeGranter +
              new PasswordGranter +
              new ClientCredentialsGranter +
              new RefreshTokenGranter

val params = Map("some_oauth_param" -> "value")
                
val response = granter(params)

This even allows you to create your custom granters. The response of a granter will be a Future[TokenResponse] containing a validation error or a new issued token info.

Akka Http integration

If you are using the akka http module you can extend or import OAuth2Support to enable implicit conversions for authorizers and granters. For example:

import OAuth2Support._
...
(path("authorize") & post & parameterMap) { params =>
    val user = ...
    authorizer.route(user, params) // ToEntityMarshaller[OAuthError] required
}
...
(path("token") & post & entity(as[FormData])) { form =>
    granter.route(form.fields.toMap)      
}

DataManager implementation

TODO

oauth2.0-scala's People

Contributors

algd avatar masseguillaume avatar

Watchers

James Cloos avatar Alexander Lomov avatar

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.