Skip to content

Commit

Permalink
use latest scalafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
tsuyoshizawa committed Sep 20, 2023
1 parent d66a7a7 commit dff5a31
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 104 deletions.
3 changes: 2 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
version = 2.7.5
version = 3.7.14
project.git = true
runner.dialect = scala3
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
129 changes: 65 additions & 64 deletions src/main/scala/scalaoauth2/provider/AuthorizationHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,70 +6,58 @@ import scala.concurrent.Future
*
* <h3>[Authorization phases]</h3>
*
* <h4>Authorization Code Grant</h4>
* <ul>
* <li>validateClient(request)</li>
* <li>findAuthInfoByCode(code)</li>
* <li>deleteAuthCode(code)</li>
* <li>getStoredAccessToken(authInfo)</li>
* <li>refreshAccessToken(authInfo, token)</li>
* <li>createAccessToken(authInfo)</li>
* </ul>
* <h4>Authorization Code Grant</h4> <ul> <li>validateClient(request)</li>
* <li>findAuthInfoByCode(code)</li> <li>deleteAuthCode(code)</li>
* <li>getStoredAccessToken(authInfo)</li> <li>refreshAccessToken(authInfo,
* token)</li> <li>createAccessToken(authInfo)</li> </ul>
*
* <h4>Refresh Token Grant</h4>
* <ul>
* <li>validateClient(clientCredential, grantType)</li>
* <li>findAuthInfoByRefreshToken(refreshToken)</li>
* <li>refreshAccessToken(authInfo, refreshToken)</li>
* </ul>
* <h4>Refresh Token Grant</h4> <ul> <li>validateClient(clientCredential,
* grantType)</li> <li>findAuthInfoByRefreshToken(refreshToken)</li>
* <li>refreshAccessToken(authInfo, refreshToken)</li> </ul>
*
* <h4>Resource Owner Password Credentials Grant</h4>
* <ul>
* <li>validateClient(request)</li>
* <li>findUser(request)</li>
* <li>getStoredAccessToken(authInfo)</li>
* <li>refreshAccessToken(authInfo, token)</li>
* <li>createAccessToken(authInfo)</li>
* </ul>
* <h4>Resource Owner Password Credentials Grant</h4> <ul>
* <li>validateClient(request)</li> <li>findUser(request)</li>
* <li>getStoredAccessToken(authInfo)</li> <li>refreshAccessToken(authInfo,
* token)</li> <li>createAccessToken(authInfo)</li> </ul>
*
* <h4>Client Credentials Grant</h4>
* <ul>
* <li>validateClient(request)</li>
* <li>findUser(request)</li>
* <li>getStoredAccessToken(authInfo)</li>
* <li>refreshAccessToken(authInfo, token)</li>
* <li>createAccessToken(authInfo)</li>
* </ul>
* <h4>Client Credentials Grant</h4> <ul> <li>validateClient(request)</li>
* <li>findUser(request)</li> <li>getStoredAccessToken(authInfo)</li>
* <li>refreshAccessToken(authInfo, token)</li>
* <li>createAccessToken(authInfo)</li> </ul>
*
* <h4>Implicit Grant</h4>
* <ul>
* <li>validateClient(request)</li>
* <li>findUser(request)</li>
* <li>getStoredAccessToken(authInfo)</li>
* <li>createAccessToken(authInfo)</li>
* </ul>
* <h4>Implicit Grant</h4> <ul> <li>validateClient(request)</li>
* <li>findUser(request)</li> <li>getStoredAccessToken(authInfo)</li>
* <li>createAccessToken(authInfo)</li> </ul>
*/
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],
Expand All @@ -78,24 +66,30 @@ 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]

/** Returns stored access token by authorized information.
*
* 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],
Expand All @@ -104,30 +98,37 @@ 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]

/** Find authorized information by refresh token.
*
* 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
Expand Down
27 changes: 18 additions & 9 deletions src/main/scala/scalaoauth2/provider/AuthorizationRequest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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")

Expand Down
39 changes: 26 additions & 13 deletions src/main/scala/scalaoauth2/provider/DataHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 7 additions & 5 deletions src/main/scala/scalaoauth2/provider/GrantHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand Down
21 changes: 12 additions & 9 deletions src/main/scala/scalaoauth2/provider/ProtectedResourceHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,32 @@ package scalaoauth2.provider

import scala.concurrent.Future

/** Provide access to <b>Protected Resource</b> phase support for using OAuth 2.0.
/** Provide access to <b>Protected Resource</b> phase support for using OAuth
* 2.0.
*
* <h3>[Access to Protected Resource phase]</h3>
* <ul>
* <li>findAccessToken(token)</li>
* <li>findAuthInfoByAccessToken(token)</li>
* <h3>[Access to Protected Resource phase]</h3> <ul>
* <li>findAccessToken(token)</li> <li>findAuthInfoByAccessToken(token)</li>
* </ul>
*/
trait ProtectedResourceHandler[+U] {

/** Find authorized information by access token.
*
* @param accessToken This value is AccessToken.
* @return Return authorized information if the parameter is available.
* @param accessToken
* This value is AccessToken.
* @return
* Return authorized information if the parameter is available.
*/
def findAuthInfoByAccessToken(
accessToken: AccessToken
): Future[Option[AuthInfo[U]]]

/** Find AccessToken object by access token code.
*
* @param token Client sends access token which is created by system.
* @return Return access token that matched the token.
* @param token
* Client sends access token which is created by system.
* @return
* Return access token that matched the token.
*/
def findAccessToken(token: String): Future[Option[AccessToken]]

Expand Down
Loading

0 comments on commit dff5a31

Please sign in to comment.