"github.com/ethereum/go-ethereum/ethclient"
"github.com/dapperlabs/dappauth"
// AuthenticationHandler ..
type AuthenticationHandler struct {
// NewAuthenticationHandler ..
func NewAuthenticationHandler(rawurl string) (*AuthenticationHandler, error) {
client, err := ethclient.Dial(rawurl)
return &AuthenticationHandler{client: client}, nil
// ServeHTTP serves just a single route for authentication as an example
func (a *AuthenticationHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
challenge := r.PostFormValue("challenge")
signature := r.PostFormValue("signature")
addrHex := r.PostFormValue("addrHex")
authenticator := dappauth.NewAuthenticator(r.Context(), a.client)
isAuthorizedSigner, err := authenticator.IsAuthorizedSigner(challenge, signature, addrHex)
// return a 5XX status code
// return a 4XX status code
// create an authenticated session for address
// return a 2XX status code
handler, err := NewAuthenticationHandler("https://mainnet.infura.io")
log.Fatal(http.ListenAndServe(":8080", handler))