start work on authorize endpoint

pull/9158/head
Niklas Fiekas 2021-06-15 00:05:27 +02:00
parent 8adb74cee7
commit 633e743186
4 changed files with 63 additions and 0 deletions

View File

@ -122,6 +122,7 @@ final class LilaComponents(ctx: ApplicationLoader.Context) extends BuiltInCompon
lazy val mod: Mod = wire[Mod]
lazy val gameMod: GameMod = wire[GameMod]
lazy val notifyC: Notify = wire[Notify]
lazy val oAuth: OAuth = wire[OAuth]
lazy val oAuthApp: OAuthApp = wire[OAuthApp]
lazy val oAuthToken: OAuthToken = wire[OAuthToken]
lazy val options: Options = wire[Options]

View File

@ -0,0 +1,26 @@
package controllers
import views._
import lila.app._
import lila.oauth.AuthenticationRequest
final class OAuth(env: Env) extends LilaController(env) {
//private val tokenApi = env.oAuth.tokenApi
def authorize =
Open { implicit ctx =>
val request = AuthenticationRequest.Raw(
responseType = get("response_type", ctx.req),
redirectUri = get("redirect_uri", ctx.req),
state = get("state", ctx.req),
codeChallenge = get("code_challenge", ctx.req),
codeChallengeMethod = get("code_challenge_method", ctx.req),
scope = get("scope", ctx.req)
)
ctx.me.fold(Redirect(routes.Auth.login).fuccess) { me =>
Ok("hello").fuccess
}
}
}

View File

@ -712,6 +712,7 @@ GET /account/info controllers.Account.info
GET /account/now-playing controllers.Account.nowPlaying
# OAuth
GET /oauth/authorize controllers.OAuth.authorize
GET /account/oauth/token controllers.OAuthToken.index
GET /account/oauth/token/create controllers.OAuthToken.create
POST /account/oauth/token/create controllers.OAuthToken.createApply

View File

@ -0,0 +1,35 @@
package lila.oauth
import cats.data.Validated
object AuthenticationRequest {
case class Error(error: String, description: String, state: Option[String])
case class Raw(
state: Option[String],
redirectUri: Option[String],
responseType: Option[String],
codeChallenge: Option[String],
codeChallengeMethod: Option[String],
scope: Option[String]) {
def validate: Validated[Error, Prepared] = {
for {
redirectUri <- redirectUri.toValid(Error("invalid_request", "redirect_uri required", state))
_ <-
responseType.toValid(Error("invalid_request", "response_type required", state))
.ensure(Error("invalid_request", "supports only response_type 'code'", state))(_ == "code")
codeChallenge <- codeChallenge.toValid(Error("invalid_request", "code_challenge required", state))
_ <-
codeChallengeMethod.toValid(Error("invalid_request", "code_challenge_method required", state))
.ensure(Error("invalid_request", "supports only code_challenge_method 'S256'", state))(_ == "S256")
} yield Prepared(redirectUri, state, codeChallenge, Nil)
}
}
case class Prepared(
redirectUri: String,
state: Option[String],
codeChallenge: String,
scopes: List[OAuthScope]
)
}