-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from t2v/feature/cookie_max_age
Supported cookie max age
- Loading branch information
Showing
42 changed files
with
864 additions
and
338 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,4 +40,6 @@ trait AuthConfig { | |
|
||
lazy val cookiePathOption: String = "/" | ||
|
||
lazy val isTransientCookie: Boolean = false | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
module/src/main/scala/jp/t2v/lab/play2/auth/CookieSupport.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package jp.t2v.lab.play2.auth | ||
|
||
import play.api.libs.Crypto | ||
import play.api.mvc.{Result, Cookie} | ||
|
||
trait CookieSupport { self: AuthConfig => | ||
|
||
def verifyHmac(cookie: Cookie): Option[String] = { | ||
val (hmac, value) = cookie.value.splitAt(40) | ||
if (Crypto.sign(value) == hmac) Some(value) else None | ||
} | ||
|
||
def bakeCookie(token: String)(result: Result): Result = { | ||
val value = Crypto.sign(token) + token | ||
val maxAge = if (isTransientCookie) None else Some(sessionTimeoutInSeconds) | ||
result.withCookies(Cookie(cookieName, value, maxAge, cookiePathOption, cookieDomainOption, cookieSecureOption, cookieHttpOnlyOption)) | ||
} | ||
|
||
} | ||
|
16 changes: 0 additions & 16 deletions
16
module/src/main/scala/jp/t2v/lab/play2/auth/CookieUtil.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
package jp.t2v.lab.play2 | ||
|
||
import play.api.mvc.Result | ||
|
||
package object auth { | ||
|
||
type AuthenticityToken = String | ||
|
||
type CookieUpdater = Result => Result | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.