Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use existing cookie to authenticate an API request #16

Open
sammit20 opened this issue Jul 9, 2018 · 1 comment
Open

Use existing cookie to authenticate an API request #16

sammit20 opened this issue Jul 9, 2018 · 1 comment

Comments

@sammit20
Copy link

sammit20 commented Jul 9, 2018

Is there any way to authenticate using existing cookie and gets details from the API request? I am very new to golang, Also went through the Chapter 29 but couldn't relate to the case I am working on. If you have reading on that can you please point it out?

My Case:
I want to connect to the REST API of remote server via golang. However the authentication to the api is via cookie only. So need to pass the existing cookie information to get authenticated and pull out the details.

@tonyjafar
Copy link

req, err := http.NewRequest("GET", "/signout", nil)
if err != nil {
t.Fatal(err.Error())
}
res := httptest.NewRecorder()

handler := http.HandlerFunc(signout)
c := &http.Cookie{
	Name:   "session",
	Value:  cookieToSet,
	MaxAge: cAge,
}
req.AddCookie(c)
handler.ServeHTTP(res, req)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants