2021-06-16 05:54:38 -06:00
|
|
|
package lila.oauth
|
|
|
|
|
|
|
|
import cats.data.Validated
|
|
|
|
import lila.user.User
|
|
|
|
|
|
|
|
object AccessTokenRequest {
|
|
|
|
import Protocol._
|
|
|
|
|
|
|
|
case class Raw(
|
|
|
|
grantType: Option[String],
|
|
|
|
code: Option[String],
|
2021-06-16 07:45:49 -06:00
|
|
|
codeVerifier: Option[String],
|
2021-06-16 05:54:38 -06:00
|
|
|
redirectUri: Option[String],
|
|
|
|
clientId: Option[String],
|
|
|
|
) {
|
|
|
|
def prepare: Validated[Error, Prepared] =
|
|
|
|
for {
|
|
|
|
grantType <- grantType.toValid(Error.GrantTypeRequired).andThen(GrantType.from)
|
|
|
|
code <- code.map(AuthorizationCode.apply).toValid(Error.CodeRequired)
|
2021-06-16 07:45:49 -06:00
|
|
|
codeVerifier <- codeVerifier.map(CodeVerifier.apply).toValid(Error.CodeVerifierRequired)
|
|
|
|
redirectUri <- redirectUri.map(UncheckedRedirectUri.apply).toValid(Error.RedirectUriRequired)
|
2021-06-16 05:54:38 -06:00
|
|
|
clientId <- clientId.map(ClientId.apply).toValid(Error.ClientIdRequired)
|
2021-06-16 07:45:49 -06:00
|
|
|
} yield Prepared(grantType, code, codeVerifier, redirectUri, clientId)
|
2021-06-16 05:54:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
case class Prepared(
|
|
|
|
grantType: GrantType,
|
|
|
|
code: AuthorizationCode,
|
2021-06-16 07:45:49 -06:00
|
|
|
codeVerifier: CodeVerifier,
|
|
|
|
redirectUri: UncheckedRedirectUri,
|
2021-06-16 05:54:38 -06:00
|
|
|
clientId: ClientId,
|
|
|
|
)
|
|
|
|
|
|
|
|
case class Granted(
|
|
|
|
userId: User.ID,
|
|
|
|
scopes: List[OAuthScope],
|
|
|
|
redirectUri: RedirectUri,
|
|
|
|
)
|
|
|
|
}
|