func clientStore(domain string) oauth2.ClientStore { return store.NewTestClientStore(&models.Client{ ID: clientID, Secret: clientSecret, Domain: domain, }) }
func TestManager(t *testing.T) { Convey("Manager test", t, func() { manager := manage.NewDefaultManager() manager.MapClientStorage(store.NewTestClientStore()) Convey("GetClient test", func() { cli, err := manager.GetClient("1") So(err, ShouldBeNil) So(cli.GetSecret(), ShouldEqual, "11") }) Convey("Memory store test", func() { manager.MapTokenStorage(store.NewMemoryTokenStore(0)) testManager(manager) }) }) }
func main() { manager := manage.NewDefaultManager() // token store manager.MapTokenStorage(store.NewMemoryTokenStore(0)) // client store manager.MapClientStorage(store.NewTestClientStore(&models.Client{ ID: "222222", Secret: "22222222", Domain: "http://localhost:9094", })) srv := server.NewServer(server.NewConfig(), manager) srv.SetUserAuthorizationHandler(userAuthorizeHandler) srv.SetInternalErrorHandler(func(r *http.Request, err error) { fmt.Println("OAuth2 Error:", r.RequestURI, err.Error()) }) http.HandleFunc("/login", loginHandler) http.HandleFunc("/auth", authHandler) 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) { err := srv.HandleTokenRequest(w, r) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) } }) log.Println("Server is running at 9096 port.") log.Fatal(http.ListenAndServe(":9096", nil)) }