-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OAuth2AsyncProvider become default provider #41
- Loading branch information
1 parent
bf75f4b
commit 664bab1
Showing
4 changed files
with
82 additions
and
61 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
47 changes: 47 additions & 0 deletions
47
play2-oauth2-provider/src/main/scala/scalaoauth2/provider/package.scala
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,47 @@ | ||
package scalaoauth2 | ||
|
||
import play.api.mvc.Result | ||
|
||
import scala.concurrent.duration._ | ||
import scala.concurrent.{Await, Future} | ||
|
||
package object provider { | ||
|
||
/** | ||
* Support synchronous Result for Playframework | ||
* | ||
* <h3>Create controller for issue access token</h3> | ||
* <code> | ||
* import scalaoauth2.provider._ | ||
* object OAuth2Controller extends Controller with OAuth2Provider { | ||
* def accessToken = Action { implicit request => | ||
* await(issueAccessToken(new MyDataHandler())) | ||
* } | ||
* } | ||
* </code> | ||
* | ||
* <h3>Register routes</h3> | ||
* <code> | ||
* POST /oauth2/access_token controllers.OAuth2Controller.accessToken | ||
* </code> | ||
* | ||
* <h3>Authorized</h3> | ||
* <code> | ||
* import scalaoauth2.provider._ | ||
* object BookController extends Controller with OAuthProvider { | ||
* def list = Action { implicit request => | ||
* await(authorize(new MyDataHandler()) { authInfo => | ||
* val user = authInfo.user // User is defined on your system | ||
* // access resource for the user | ||
* Future.successful(Ok) | ||
* }) | ||
* } | ||
* } | ||
* </code> | ||
* @param f callback | ||
* @param timeout maximum wait time | ||
* @return Await and return the result. | ||
*/ | ||
def await(f: Future[Result], timeout: Duration = 60.seconds): Result = Await.result(f, timeout) | ||
|
||
} |
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