https://github.com/dapperlabs/dappauth
A Go util for ERC-1654
https://github.com/dapperlabs/dappauth
Last synced: 5 months ago
JSON representation
A Go util for ERC-1654
- Host: GitHub
- URL: https://github.com/dapperlabs/dappauth
- Owner: dapperlabs
- License: mit
- Created: 2018-10-16T07:29:11.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-04-16T22:04:05.000Z (about 5 years ago)
- Last Synced: 2024-06-19T02:58:57.792Z (almost 2 years ago)
- Language: Go
- Homepage: https://github.com/ethereum/EIPs/issues/1654
- Size: 73.2 KB
- Stars: 8
- Watchers: 60
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.com/dapperlabs/dappauth)
[](https://coveralls.io/github/dapperlabs/dappauth?branch=master)
# dappauth
## Example usage within a webserver
```Go
package main
import (
"log"
"net/http"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/dapperlabs/dappauth"
)
// AuthenticationHandler ..
type AuthenticationHandler struct {
client *ethclient.Client
}
// NewAuthenticationHandler ..
func NewAuthenticationHandler(rawurl string) (*AuthenticationHandler, error) {
client, err := ethclient.Dial(rawurl)
if err != nil {
return nil, err
}
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)
if err != nil {
// return a 5XX status code
}
if !isAuthorizedSigner{
// return a 4XX status code
}
// create an authenticated session for address
// return a 2XX status code
}
func main() {
handler, err := NewAuthenticationHandler("https://mainnet.infura.io")
if err != nil {
log.Fatal(err)
}
log.Fatal(http.ListenAndServe(":8080", handler))
}
```