Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/akhenakh/goth
Go OAuth 1.0a 2 legs provider
https://github.com/akhenakh/goth
Last synced: 24 days ago
JSON representation
Go OAuth 1.0a 2 legs provider
- Host: GitHub
- URL: https://github.com/akhenakh/goth
- Owner: akhenakh
- License: mit
- Created: 2014-07-01T00:00:01.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-11-30T21:39:23.000Z (almost 10 years ago)
- Last Synced: 2024-06-19T18:12:21.842Z (5 months ago)
- Language: Go
- Homepage:
- Size: 164 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
goth
====Go OAuth 1.0a 2 legs provider with oauth_body_hash support.
Just provide a function conforms to `OAuthCheckerFunc` Goth will authenticate your requests.
You can get the userId return by your auth function inside the handler at `r.URL.User.Username()`.
To enable oauth_body_hash check set `WithBodyHash` to true.
```go
package mainimport (
"fmt"
"net/http""github.com/akhenakh/goth"
)func myAuthFunc(consumerKey string) (userId string, consumerSecret string) {
if consumerKey == "ckey" {
return "myusername", "csecret"
}
return "", ""
}func helloFunc(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "hello "+r.URL.User.Username())
}func main() {
o := goth.OAuth1{CheckerFunc: myAuthFunc}
myHandler := http.HandlerFunc(helloFunc)
http.ListenAndServe(":3000", o.AuthProtect(myHandler))
}
```