PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, November 14, 2022

[FIXED] How to specify the domain of cookie with Scala and Play

 November 14, 2022     cookies, playframework, scala, session-cookies, subdomain     No comments   

Issue

I want cookies which is set from test.domain.com to be set for .domain.com so that that it can still be used from anothertest.domain.com. Basically cookies should be shared between subdomains.

I called backend deployed at test.domain.com and set cookies with OK response as follows:


Ok("some response").withCookies(Cookie("id", id), Cookie("token", token))

And in application.conf I have set the session domain to ".domain.com"-


session {
\#Sets the cookie to be sent only over HTTPS.
\#secure = true

\#Sets the cookie to be accessed only by the server.
\#httpOnly = true

\#Sets the max-age field of the cookie to 5 minutes.
\#NOTE: this only sets when the browser will discard the cookie. Play will consider any
\#cookie value with a valid signature to be a valid session forever. To implement a server side session timeout,
\#you need to put a timestamp in the session and check it at regular intervals to possibly expire it.
\#maxAge = 300

\#Sets the domain on the session cookie.
domain = ".domain.com"
}

However, the cookie is being set for test.domain.com rather than .domain.com. I want to use this cookie with anothertest.domain.com .
Can you please help me with this.


Solution

You don't have to change the configuration, you can add all attributes of a cookie when creating it.

Cookie("bla", bla).withDomain(xxx)
// Or
Cookie("bla", bla, domain = XXX)

(Not sure of exact name, I don't have documentation with me right now)



Answered By - Gaël J
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing