Library for Twitter Digits, it acts as a delegator (for more information : https://dev.twitter.com/oauth/echo).
This package requires Go +1.7
package main
import (
"net/http"
"gopkg.in/bamarni/digits.v1"
)
func main() {
identity, err := digits.Verify(
"https://api.digits.com/1.1/sdk/account.json",
"OAuth oauth_consumer_key=[...] oauth_*=[...]",
nil,
)
// println(identity.PhoneNumber)
// ...
}
The default handler throws a HTTP 401 response in case of authentication failure. Otherwise, user identity can be retrieved through the request context :
package main
import (
"net/http"
"github.com/urfave/negroni"
"gopkg.in/bamarni/digits.v1"
)
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
identity := r.Context().Value(digits.Key).(*digits.Identity)
fmt.Fprintf(w, "Can I reach you at %s?", identity.PhoneNumber)
})
n := negroni.Classic()
n.Use(digits.Default())
n.UseHandler(mux)
http.ListenAndServe(":3000", n)
}
In dev environment, you can skip authentication to Digits API and use a static phone number instead :
digitsMiddleware := digits.New(digits.Options{
PhoneNumber: "+33123456789",
})
n := negroni.New(digitsMiddleware)
// ...