diff --git a/.scalafmt.conf b/.scalafmt.conf index 2396610..09de336 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,2 +1,3 @@ -version = 2.7.5 +version = 3.7.14 project.git = true +runner.dialect = scala3 diff --git a/project/plugins.sbt b/project/plugins.sbt index bcda4ae..7d517ef 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1 +1 @@ -addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2") diff --git a/src/main/scala/scalaoauth2/provider/AuthorizationHandler.scala b/src/main/scala/scalaoauth2/provider/AuthorizationHandler.scala index 425a93f..f4f84ca 100644 --- a/src/main/scala/scalaoauth2/provider/AuthorizationHandler.scala +++ b/src/main/scala/scalaoauth2/provider/AuthorizationHandler.scala @@ -6,70 +6,58 @@ import scala.concurrent.Future * *

[Authorization phases]

* - *

Authorization Code Grant

- * + *

Authorization Code Grant

* - *

Refresh Token Grant

- * + *

Refresh Token Grant

* - *

Resource Owner Password Credentials Grant

- * + *

Resource Owner Password Credentials Grant

* - *

Client Credentials Grant

- * + *

Client Credentials Grant

* - *

Implicit Grant

- * + *

Implicit Grant

*/ trait AuthorizationHandler[U] { - /** Verify proper client with parameters for issue an access token. - * Note that per the OAuth Specification, a Client may be valid if it only contains a client ID but no client - * secret (common with Public Clients). However, if the registered client has a client secret value the specification - * requires that a client secret must always be provided and verified for that client ID. + /** Verify proper client with parameters for issue an access token. Note that + * per the OAuth Specification, a Client may be valid if it only contains a + * client ID but no client secret (common with Public Clients). However, if + * the registered client has a client secret value the specification requires + * that a client secret must always be provided and verified for that client + * ID. * - * @param maybeCredential client credential parsed from request - * @param request Request sent by client. - * @return true if request is a regular client, false if request is a illegal client. + * @param maybeCredential + * client credential parsed from request + * @param request + * Request sent by client. + * @return + * true if request is a regular client, false if request is a illegal + * client. */ def validateClient( maybeCredential: Option[ClientCredential], request: AuthorizationRequest ): Future[Boolean] - /** Authenticate the user that issued the authorization request. - * Client credential, Password and Implicit Grant call this method. + /** Authenticate the user that issued the authorization request. Client + * credential, Password and Implicit Grant call this method. * - * @param maybeCredential client credential parsed from request - * @param request Request sent by client. + * @param maybeCredential + * client credential parsed from request + * @param request + * Request sent by client. */ def findUser( maybeCredential: Option[ClientCredential], @@ -78,8 +66,10 @@ trait AuthorizationHandler[U] { /** Creates a new access token by authorized information. * - * @param authInfo This value is already authorized by system. - * @return Access token returns to client. + * @param authInfo + * This value is already authorized by system. + * @return + * Access token returns to client. */ def createAccessToken(authInfo: AuthInfo[U]): Future[AccessToken] @@ -87,15 +77,19 @@ trait AuthorizationHandler[U] { * * If want to create new access token then have to return None * - * @param authInfo This value is already authorized by system. - * @return Access token returns to client. + * @param authInfo + * This value is already authorized by system. + * @return + * Access token returns to client. */ def getStoredAccessToken(authInfo: AuthInfo[U]): Future[Option[AccessToken]] /** Creates a new access token by refreshToken. * - * @param authInfo This value is already authorized by system. - * @return Access token returns to client. + * @param authInfo + * This value is already authorized by system. + * @return + * Access token returns to client. */ def refreshAccessToken( authInfo: AuthInfo[U], @@ -104,21 +98,26 @@ trait AuthorizationHandler[U] { /** Find authorized information by authorization code. * - * If you don't support Authorization Code Grant then doesn't need implementing. + * If you don't support Authorization Code Grant then doesn't need + * implementing. * - * @param code Client sends authorization code which is registered by system. - * @return Return authorized information that matched the code. + * @param code + * Client sends authorization code which is registered by system. + * @return + * Return authorized information that matched the code. */ def findAuthInfoByCode(code: String): Future[Option[AuthInfo[U]]] /** Deletes an authorization code. * - * Called when an AccessToken has been successfully issued via an authorization code. + * Called when an AccessToken has been successfully issued via an + * authorization code. * - * If you don't support Authorization Code Grant, then you don't need to implement this - * method. + * If you don't support Authorization Code Grant, then you don't need to + * implement this method. * - * @param code Client-sent authorization code + * @param code + * Client-sent authorization code */ def deleteAuthCode(code: String): Future[Unit] @@ -126,8 +125,10 @@ trait AuthorizationHandler[U] { * * If you don't support Refresh Token Grant then doesn't need implementing. * - * @param refreshToken Client sends refresh token which is created by system. - * @return Return authorized information that matched the refresh token. + * @param refreshToken + * Client sends refresh token which is created by system. + * @return + * Return authorized information that matched the refresh token. */ def findAuthInfoByRefreshToken( refreshToken: String diff --git a/src/main/scala/scalaoauth2/provider/AuthorizationRequest.scala b/src/main/scala/scalaoauth2/provider/AuthorizationRequest.scala index 6ee921f..94ebcbd 100644 --- a/src/main/scala/scalaoauth2/provider/AuthorizationRequest.scala +++ b/src/main/scala/scalaoauth2/provider/AuthorizationRequest.scala @@ -67,8 +67,10 @@ case class RefreshTokenRequest(request: AuthorizationRequest) /** returns refresh_token. * - * @return code. - * @throws InvalidRequest if the parameter is not found + * @return + * code. + * @throws InvalidRequest + * if the parameter is not found */ def refreshToken: String = requireParam("refresh_token") } @@ -78,15 +80,19 @@ case class PasswordRequest(request: AuthorizationRequest) /** returns username. * - * @return username. - * @throws InvalidRequest if the parameter is not found + * @return + * username. + * @throws InvalidRequest + * if the parameter is not found */ def username = requireParam("username") /** returns password. * - * @return password. - * @throws InvalidRequest if the parameter is not found + * @return + * password. + * @throws InvalidRequest + * if the parameter is not found */ def password = requireParam("password") } @@ -99,14 +105,17 @@ case class AuthorizationCodeRequest(request: AuthorizationRequest) /** returns code. * - * @return code. - * @throws InvalidRequest if code is not found + * @return + * code. + * @throws InvalidRequest + * if code is not found */ def code: String = requireParam("code") /** Returns redirect_uri. * - * @return redirect_uri + * @return + * redirect_uri */ def redirectUri: Option[String] = param("redirect_uri") diff --git a/src/main/scala/scalaoauth2/provider/DataHandler.scala b/src/main/scala/scalaoauth2/provider/DataHandler.scala index 0580294..2ca5429 100644 --- a/src/main/scala/scalaoauth2/provider/DataHandler.scala +++ b/src/main/scala/scalaoauth2/provider/DataHandler.scala @@ -12,12 +12,19 @@ trait DataHandler[U] /** Access token * - * @param token Access token is used to authentication. - * @param refreshToken Refresh token is used to re-issue access token. - * @param scope Inform the client of the scope of the access token issued. - * @param lifeSeconds Life of the access token since its creation. In seconds. - * @param createdAt Access token is created date. - * @param params Additional parameters to add information/restriction on given Access token. + * @param token + * Access token is used to authentication. + * @param refreshToken + * Refresh token is used to re-issue access token. + * @param scope + * Inform the client of the scope of the access token issued. + * @param lifeSeconds + * Life of the access token since its creation. In seconds. + * @param createdAt + * Access token is created date. + * @param params + * Additional parameters to add information/restriction on given Access + * token. */ case class AccessToken( token: String, @@ -52,19 +59,25 @@ object CodeChallengeMethod { value match { case "S256" => Success(S256) case "plain" => Success(Plain) - case _ => Failure(new InvalidRequest("transform algorithm not supported")) + case _ => Failure(new InvalidRequest("transform algorithm not supported")) } } } /** Authorized information * - * @param user Authorized user which is registered on system. - * @param clientId Using client id which is registered on system. - * @param scope Inform the client of the scope of the access token issued. - * @param redirectUri This value is used by Authorization Code Grant. - * @param codeChallenge This value is used by Authorization Code Grant for PKCE support. - * @param codeChallengeMethod This value is used by Authorization Code Grant for PKCE support. + * @param user + * Authorized user which is registered on system. + * @param clientId + * Using client id which is registered on system. + * @param scope + * Inform the client of the scope of the access token issued. + * @param redirectUri + * This value is used by Authorization Code Grant. + * @param codeChallenge + * This value is used by Authorization Code Grant for PKCE support. + * @param codeChallengeMethod + * This value is used by Authorization Code Grant for PKCE support. */ case class AuthInfo[+U]( user: U, diff --git a/src/main/scala/scalaoauth2/provider/GrantHandler.scala b/src/main/scala/scalaoauth2/provider/GrantHandler.scala index 8c413f0..4b8b3b9 100644 --- a/src/main/scala/scalaoauth2/provider/GrantHandler.scala +++ b/src/main/scala/scalaoauth2/provider/GrantHandler.scala @@ -17,9 +17,11 @@ case class GrantHandlerResult[U]( trait GrantHandler { - /** Controls whether client credentials are required. Defaults to true but can be overridden to be false when needed. - * Per the OAuth2 specification, client credentials are required for all grant types except password, where it is up - * to the authorization provider whether to make them required or not. + /** Controls whether client credentials are required. Defaults to true but can + * be overridden to be false when needed. Per the OAuth2 specification, + * client credentials are required for all grant types except password, where + * it is up to the authorization provider whether to make them required or + * not. */ def clientCredentialRequired = true @@ -105,8 +107,8 @@ class Password extends GrantHandler { handler: AuthorizationHandler[U] )(implicit ctx: ExecutionContext): Future[GrantHandlerResult[U]] = { - /** Given that client credentials may be optional, if they are required, they must be fully validated before - * further processing. + /** Given that client credentials may be optional, if they are required, + * they must be fully validated before further processing. */ if (clientCredentialRequired && maybeValidatedClientCred.isEmpty) { throw new InvalidRequest("Client credential is required") diff --git a/src/main/scala/scalaoauth2/provider/ProtectedResourceHandler.scala b/src/main/scala/scalaoauth2/provider/ProtectedResourceHandler.scala index b90d8ee..65b1c4d 100644 --- a/src/main/scala/scalaoauth2/provider/ProtectedResourceHandler.scala +++ b/src/main/scala/scalaoauth2/provider/ProtectedResourceHandler.scala @@ -2,20 +2,21 @@ package scalaoauth2.provider import scala.concurrent.Future -/** Provide access to Protected Resource phase support for using OAuth 2.0. +/** Provide access to Protected Resource phase support for using OAuth + * 2.0. * - *

[Access to Protected Resource phase]

- *