项目作者: sohamkamani

项目描述 :
An example of session based authentication in Go
高级语言: Go
项目地址: git://github.com/sohamkamani/go-session-auth-example.git
创建时间: 2018-03-23T13:48:32Z
项目社区:https://github.com/sohamkamani/go-session-auth-example

开源协议:

下载


Session Cookie Authentication in Go

Example repo for my post on session cookie authentication in Go

Running our application

To run this application, build and run the Go binary:

  1. go build
  2. ./go-session-auth-example

Now, using any HTTP client with support for cookies (like Postman, or your web browser) make a sign-in request with the appropriate credentials:

  1. POST http://localhost:8080/signin
  2. {"username":"user2","password":"password2"}

You can now try hitting the welcome route from the same client to get the welcome message:

  1. GET http://localhost:8080/welcome

Hit the refresh route, and then inspect the clients cookies to see the new value of the session_token:

  1. POST http://localhost:8080/refresh

Finally, call the logout route to clear session data:

  1. GET http://localhost:8080/logout

Calling the welcome and refresh routes after this will result in a 401 error.