@@ -112,26 +112,36 @@ class PandaAuthenticationProvider(
112112 override def flushToken : Option [(RequestHeader , Result ) => Result ] = Some ((rh, _) => processLogout(rh))
113113
114114 val PandaCookieKey : TypedKey [Cookie ] = TypedKey [Cookie ](" PandaCookie" )
115+ val OriginKey : TypedKey [String ] = TypedKey [String ](" Origin" )
116+
117+ private def withPersistedOrigin (request : Principal ): WSRequest => WSRequest = { wsRequest =>
118+ request.attributes.get(OriginKey ) match {
119+ case Some (origin) => wsRequest.withHttpHeaders((" Origin" , origin))
120+ case None => wsRequest
121+ }
122+ }
123+
124+ private def withPersistedCookie (request : Principal ): Either [String , WSRequest => WSRequest ] = {
125+ val cookieName = panDomainSettings.settings.cookieSettings.cookieName
126+ request.attributes.get(PandaCookieKey ) match {
127+ case Some (cookie) => Right (wsRequest => wsRequest.addCookies(DefaultWSCookie (cookieName, cookie.value)))
128+ case None => Left (s " Pan domain cookie $cookieName is missing in principal. " )
129+ }
130+ }
115131
116132 /**
117133 * A function that allows downstream API calls to be made using the credentials of the inflight request
118134 *
119135 * @param request The request header of the inflight call
120136 * @return A function that adds appropriate data to a WSRequest
121137 */
122- override def onBehalfOf (request : Principal ): Either [String , WSRequest => WSRequest ] = {
123- val cookieName = panDomainSettings.settings.cookieSettings.cookieName
124- request.attributes.get(PandaCookieKey ) match {
125- case Some (cookie) => Right { wsRequest : WSRequest =>
126- wsRequest.addCookies(DefaultWSCookie (cookieName, cookie.value))
127- }
128- case None => Left (s " Pan domain cookie $cookieName is missing in principal. " )
129- }
130- }
138+ override def onBehalfOf (request : Principal ): Either [String , WSRequest => WSRequest ] =
139+ withPersistedCookie(request).map(_.andThen(withPersistedOrigin(request)))
131140
132141 private def gridUserFrom (pandaUser : User , request : RequestHeader ): UserPrincipal = {
133142 val maybePandaCookie : Option [TypedEntry [Cookie ]] = request.cookies.get(panDomainSettings.settings.cookieSettings.cookieName).map(TypedEntry [Cookie ](PandaCookieKey , _))
134- val attributes = TypedMap .empty + (maybePandaCookie.toSeq:_* )
143+ val maybeOrigin = request.headers.get(" Origin" ).map(TypedEntry [String ](OriginKey , _))
144+ val attributes = TypedMap (Seq (maybePandaCookie, maybeOrigin).flatten:_* )
135145 UserPrincipal (
136146 firstName = pandaUser.firstName,
137147 lastName = pandaUser.lastName,
0 commit comments