11package scalaoauth2 .provider
22
33import java .util .Date
4- import scala .concurrent .Future
4+
5+ /**
6+ * Provide accessing to data storage for using OAuth 2.0.
7+ */
8+ trait DataHandler [U ] extends AuthorizationHandler [U ] with ProtectedResourceHandler [U ]
59
610/**
711 * Access token
@@ -14,9 +18,6 @@ import scala.concurrent.Future
1418 */
1519case class AccessToken (token : String , refreshToken : Option [String ], scope : Option [String ], expiresIn : Option [Long ], createdAt : Date ) {
1620
17- /**
18- * Check expiration.
19- */
2021 def isExpired : Boolean = expiresIn.exists { expiresIn =>
2122 val now = System .currentTimeMillis()
2223 createdAt.getTime + expiresIn * 1000 <= now
@@ -33,125 +34,3 @@ case class AccessToken(token: String, refreshToken: Option[String], scope: Optio
3334 * @param redirectUri This value is used by Authorization Code Grant.
3435 */
3536case class AuthInfo [+ U ](user : U , clientId : Option [String ], scope : Option [String ], redirectUri : Option [String ])
36-
37- /**
38- * Provide accessing to data storage for using OAuth 2.0.
39- *
40- * <h3>[Authorization phases]</h3>
41- *
42- * <h4>Authorization Code Grant</h4>
43- * <ul>
44- * <li>validateClient(clientCredential, grantType)</li>
45- * <li>findAuthInfoByCode(code)</li>
46- * <li>getStoredAccessToken(authInfo)</li>
47- * <li>isAccessTokenExpired(token)</li>
48- * <li>refreshAccessToken(authInfo, token)
49- * <li>createAccessToken(authInfo)</li>
50- * </ul>
51- *
52- * <h4>Refresh Token Grant</h4>
53- * <ul>
54- * <li>validateClient(clientCredential, grantType)</li>
55- * <li>findAuthInfoByRefreshToken(refreshToken)</li>
56- * <li>refreshAccessToken(authInfo, refreshToken)</li>
57- * </ul>
58- *
59- * <h4>Resource Owner Password Credentials Grant</h4>
60- * <ul>
61- * <li>validateClient(clientCredential, grantType)</li>
62- * <li>findUser(username, password)</li>
63- * <li>getStoredAccessToken(authInfo)</li>
64- * <li>isAccessTokenExpired(token)</li>
65- * <li>refreshAccessToken(authInfo, token)
66- * <li>createAccessToken(authInfo)</li>
67- * </ul>
68- *
69- * <h4>Client Credentials Grant</h4>
70- * <ul>
71- * <li>validateClient(clientCredential, grantType)</li>
72- * <li>findClientUser(clientCredential)</li>
73- * <li>getStoredAccessToken(authInfo)</li>
74- * <li>isAccessTokenExpired(token)</li>
75- * <li>refreshAccessToken(authInfo, token)
76- * <li>createAccessToken(authInfo)</li>
77- * </ul>
78- *
79- */
80- trait DataHandler [U ] {
81-
82- /**
83- * Verify proper client with parameters for issue an access token.
84- *
85- * @param clientCredential Client sends clientId and clientSecret which are registered by application.
86- * @param grantType Client sends this value which is registered by application.
87- * @return true if request is a regular client, false if request is a illegal client.
88- */
89- def validateClient (clientCredential : ClientCredential , grantType : String ): Future [Boolean ]
90-
91- /**
92- * Find userId with username and password these are used on your system.
93- * If you don't support Resource Owner Password Credentials Grant then doesn't need implementing.
94- *
95- * @param username Client sends this value which is used on your system.
96- * @param password Client sends this value which is used on your system.
97- * @return Including UserId to Option if could find the user, None if couldn't find.
98- */
99- def findUser (username : String , password : String ): Future [Option [U ]]
100-
101- /**
102- * Creates a new access token by authorized information.
103- *
104- * @param authInfo This value is already authorized by system.
105- * @return Access token returns to client.
106- */
107- def createAccessToken (authInfo : AuthInfo [U ]): Future [AccessToken ]
108-
109- /**
110- * Returns stored access token by authorized information.
111- *
112- * If want to create new access token then have to return None
113- *
114- * @param authInfo This value is already authorized by system.
115- * @return Access token returns to client.
116- */
117- def getStoredAccessToken (authInfo : AuthInfo [U ]): Future [Option [AccessToken ]]
118-
119- /**
120- * Creates a new access token by refreshToken.
121- *
122- * @param authInfo This value is already authorized by system.
123- * @return Access token returns to client.
124- */
125- def refreshAccessToken (authInfo : AuthInfo [U ], refreshToken : String ): Future [AccessToken ]
126-
127- /**
128- * Find authorized information by authorization code.
129- *
130- * If you don't support Authorization Code Grant then doesn't need implementing.
131- *
132- * @param code Client sends authorization code which is registered by system.
133- * @return Return authorized information that matched the code.
134- */
135- def findAuthInfoByCode (code : String ): Future [Option [AuthInfo [U ]]]
136-
137- /**
138- * Find authorized information by refresh token.
139- *
140- * If you don't support Refresh Token Grant then doesn't need implementing.
141- *
142- * @param refreshToken Client sends refresh token which is created by system.
143- * @return Return authorized information that matched the refresh token.
144- */
145- def findAuthInfoByRefreshToken (refreshToken : String ): Future [Option [AuthInfo [U ]]]
146-
147- /**
148- * Find user by clientId and clientSecret.
149- *
150- * If you don't support Client Credentials Grant then doesn't need implementing.
151- *
152- * @param clientCredential Client sends clientId and clientSecret which are registered by application.
153- * @return Return user that matched both values.
154- */
155- def findClientUser (clientCredential : ClientCredential , scope : Option [String ]): Future [Option [U ]]
156-
157- }
0 commit comments