bit of experimenting and tidying
This commit is contained in:
3
internal/oauth/README.md
Normal file
3
internal/oauth/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# oauth
|
||||
|
||||
This package provides uses [go-oauth2](https://github.com/go-oauth2/oauth2) to provide [oauth2](https://www.oauth.com/) server functionality to the GoToSocial APIs.
|
@ -19,42 +19,46 @@
|
||||
package oauth
|
||||
|
||||
type Server struct {
|
||||
manager := manage.NewDefaultManager()
|
||||
// token memory store
|
||||
manager.MustTokenStorage(store.NewMemoryTokenStore())
|
||||
|
||||
// client memory store
|
||||
clientStore := store.NewClientStore()
|
||||
clientStore.Set("000000", &models.Client{
|
||||
ID: "000000",
|
||||
Secret: "999999",
|
||||
Domain: "http://localhost",
|
||||
})
|
||||
manager.MapClientStorage(clientStore)
|
||||
|
||||
srv := server.NewDefaultServer(manager)
|
||||
srv.SetAllowGetAccessRequest(true)
|
||||
srv.SetClientInfoHandler(server.ClientFormHandler)
|
||||
|
||||
srv.SetInternalErrorHandler(func(err error) (re *errors.Response) {
|
||||
log.Println("Internal Error:", err.Error())
|
||||
return
|
||||
})
|
||||
|
||||
srv.SetResponseErrorHandler(func(re *errors.Response) {
|
||||
log.Println("Response Error:", re.Error.Error())
|
||||
})
|
||||
|
||||
http.HandleFunc("/authorize", func(w http.ResponseWriter, r *http.Request) {
|
||||
err := srv.HandleAuthorizeRequest(w, r)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
})
|
||||
|
||||
http.HandleFunc("/token", func(w http.ResponseWriter, r *http.Request) {
|
||||
srv.HandleTokenRequest(w, r)
|
||||
})
|
||||
|
||||
log.Fatal(http.ListenAndServe(":9096", nil))
|
||||
}
|
||||
|
||||
func main() {
|
||||
// manager := manage.NewDefaultManager()
|
||||
// // token memory store
|
||||
// manager.MustTokenStorage(store.NewMemoryTokenStore())
|
||||
|
||||
// // client memory store
|
||||
// clientStore := store.NewClientStore()
|
||||
// clientStore.Set("000000", &models.Client{
|
||||
// ID: "000000",
|
||||
// Secret: "999999",
|
||||
// Domain: "http://localhost",
|
||||
// })
|
||||
// manager.MapClientStorage(clientStore)
|
||||
|
||||
// srv := server.NewDefaultServer(manager)
|
||||
// srv.SetAllowGetAccessRequest(true)
|
||||
// srv.SetClientInfoHandler(server.ClientFormHandler)
|
||||
|
||||
// srv.SetInternalErrorHandler(func(err error) (re *errors.Response) {
|
||||
// log.Println("Internal Error:", err.Error())
|
||||
// return
|
||||
// })
|
||||
|
||||
// srv.SetResponseErrorHandler(func(re *errors.Response) {
|
||||
// log.Println("Response Error:", re.Error.Error())
|
||||
// })
|
||||
|
||||
// http.HandleFunc("/authorize", func(w http.ResponseWriter, r *http.Request) {
|
||||
// err := srv.HandleAuthorizeRequest(w, r)
|
||||
// if err != nil {
|
||||
// http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
// }
|
||||
// })
|
||||
|
||||
// http.HandleFunc("/token", func(w http.ResponseWriter, r *http.Request) {
|
||||
// srv.HandleTokenRequest(w, r)
|
||||
// })
|
||||
|
||||
// log.Fatal(http.ListenAndServe(":9096", nil))
|
||||
}
|
||||
|
Reference in New Issue
Block a user