Azure / Azure/static-web-apps

Cookie set from API is not included in callback

Open
#382 10 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
346
Forks
67
PR merge metrics
No merged PRs in 30d

Description

Hi!

I have developed a quickstart template for Azure Static Web App / Hugo / Netlify CMS.
https://github.com/jahlen/hugo-azure-static-webapp

It implements Netlify CMS to GitHub authentication via an Azure Function (found under /api/OAuth.cs). For the OAuth authentication, I tried saving the state in a cookie, but it won't work. Here's my code where I set the cookie:

``` csharp
[FunctionName("Auth")]
public static IActionResult Auth(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
ILogger log)
{
var state = CreateRandomString();
req.HttpContext.Response.Cookies.Append(CookieName, state, new CookieOptions { HttpOnly = true, SameSite = SameSiteMode.Lax, Secure = true});
var authorizationUrl = $"{AuthorizationUrl}?response_type=code&client_id={ClientId}&redirect_uri={WebUtility.UrlEncode(RedirectUri)}&scope={WebUtility.UrlEncode(Scope)}&state={WebUtility.UrlEncode(state)}";

return new RedirectResult(authorizationUrl);
}
```

The problem is that the cookie is NOT included when the users is sent to the redirect_uri, even if it is on the same domain. If I manually go to the redirect_uri in my browser, the cookie will be included. Maybe this is a difference in behavior between strict and lax? I note that it sets *samesite* to *strict* even if I specify it to be *lax*.

![image](https://user-images.githubusercontent.com/11652570/116056328-f961ef80-a67d-11eb-85c6-fca3975e3e1a.png)

Anything wrong I am doing with the cookie?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.