summaryrefslogtreecommitdiff
path: root/internal/oauth/oauth.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/oauth/oauth.go')
-rw-r--r--internal/oauth/oauth.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/internal/oauth/oauth.go b/internal/oauth/oauth.go
index 95cf97191..11b1b57fd 100644
--- a/internal/oauth/oauth.go
+++ b/internal/oauth/oauth.go
@@ -19,4 +19,42 @@
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))
}