Compare commits
No commits in common. "703531834d493f7b969069d7076d18cc58020aed" and "9389cc0266e40f57d493ec5951f05c46715a2ec0" have entirely different histories.
703531834d
...
9389cc0266
|
@ -399,29 +399,3 @@ func TestAccessTokenWithIncorrectCode(t *testing.T) {
|
|||
|
||||
assertions.AssertStatus(t, rr, http.StatusUnauthorized)
|
||||
}
|
||||
|
||||
func TestIndieauthMetadata(t *testing.T) {
|
||||
repo, user := getSingleUserTestRepo()
|
||||
user.ResetPassword("testpassword")
|
||||
req, _ := http.NewRequest("GET", user.IndieauthMetadataUrl(), nil)
|
||||
rr := httptest.NewRecorder()
|
||||
router := main.SingleUserRouter(&repo)
|
||||
router.ServeHTTP(rr, req)
|
||||
|
||||
assertions.AssertStatus(t, rr, http.StatusOK)
|
||||
// parse response as json
|
||||
type responseType struct {
|
||||
Issuer string `json:"issuer"`
|
||||
AuthorizationEndpoint string `json:"authorization_endpoint"`
|
||||
TokenEndpoint string `json:"token_endpoint"`
|
||||
CodeChallengeMethodsSupported []string `json:"code_challenge_methods_supported"`
|
||||
ScopesSupported []string `json:"scopes_supported"`
|
||||
ResponseTypesSupported []string `json:"response_types_supported"`
|
||||
GrantTypesSupported []string `json:"grant_types_supported"`
|
||||
}
|
||||
var response responseType
|
||||
json.Unmarshal(rr.Body.Bytes(), &response)
|
||||
assertions.AssertEqual(t, response.Issuer, user.FullUrl())
|
||||
assertions.AssertEqual(t, response.AuthorizationEndpoint, user.AuthUrl())
|
||||
assertions.AssertEqual(t, response.TokenEndpoint, user.TokenUrl())
|
||||
}
|
||||
|
|
|
@ -60,43 +60,6 @@ func userIndexHandler(repo *owl.Repository) func(http.ResponseWriter, *http.Requ
|
|||
}
|
||||
}
|
||||
|
||||
func userAuthMetadataHandler(repo *owl.Repository) func(http.ResponseWriter, *http.Request, httprouter.Params) {
|
||||
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
user, err := getUserFromRepo(repo, ps)
|
||||
if err != nil {
|
||||
println("Error getting user: ", err.Error())
|
||||
notFoundHandler(repo)(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
Issuer string `json:"issuer"`
|
||||
AuthorizationEndpoint string `json:"authorization_endpoint"`
|
||||
TokenEndpoint string `json:"token_endpoint"`
|
||||
CodeChallengeMethodsSupported []string `json:"code_challenge_methods_supported"`
|
||||
ScopesSupported []string `json:"scopes_supported"`
|
||||
ResponseTypesSupported []string `json:"response_types_supported"`
|
||||
GrantTypesSupported []string `json:"grant_types_supported"`
|
||||
}
|
||||
response := Response{
|
||||
Issuer: user.FullUrl(),
|
||||
AuthorizationEndpoint: user.AuthUrl(),
|
||||
TokenEndpoint: user.TokenUrl(),
|
||||
CodeChallengeMethodsSupported: []string{"S256", "plain"},
|
||||
ScopesSupported: []string{"profile"},
|
||||
ResponseTypesSupported: []string{"code"},
|
||||
GrantTypesSupported: []string{"authorization_code"},
|
||||
}
|
||||
jsonData, err := json.Marshal(response)
|
||||
if err != nil {
|
||||
println("Error marshalling json: ", err.Error())
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte("Internal server error"))
|
||||
}
|
||||
w.Write(jsonData)
|
||||
}
|
||||
}
|
||||
|
||||
func userAuthHandler(repo *owl.Repository) func(http.ResponseWriter, *http.Request, httprouter.Params) {
|
||||
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
user, err := getUserFromRepo(repo, ps)
|
||||
|
|
|
@ -23,7 +23,6 @@ func Router(repo *owl.Repository) http.Handler {
|
|||
router.GET("/user/:user/posts/:post/", postHandler(repo))
|
||||
router.GET("/user/:user/posts/:post/media/*filepath", postMediaHandler(repo))
|
||||
router.POST("/user/:user/webmention/", userWebmentionHandler(repo))
|
||||
router.GET("/user/:user/.well-known/oauth-authorization-server", userAuthMetadataHandler(repo))
|
||||
router.NotFound = http.HandlerFunc(notFoundHandler(repo))
|
||||
return router
|
||||
}
|
||||
|
@ -41,7 +40,6 @@ func SingleUserRouter(repo *owl.Repository) http.Handler {
|
|||
router.GET("/posts/:post/", postHandler(repo))
|
||||
router.GET("/posts/:post/media/*filepath", postMediaHandler(repo))
|
||||
router.POST("/webmention/", userWebmentionHandler(repo))
|
||||
router.GET("/.well-known/oauth-authorization-server", userAuthMetadataHandler(repo))
|
||||
router.NotFound = http.HandlerFunc(notFoundHandler(repo))
|
||||
return router
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
<link rel="stylesheet" href="/static/pico.min.css">
|
||||
<link rel="webmention" href="{{ .User.WebmentionUrl }}">
|
||||
{{ if .User.AuthUrl }}
|
||||
<link rel="indieauth-metadata" href="{{ .User.IndieauthMetadataUrl }}">
|
||||
<link rel="authorization_endpoint" href="{{ .User.AuthUrl}}">
|
||||
<link rel="token_endpoint" href="{{ .User.TokenUrl}}">
|
||||
{{ end }}
|
||||
|
|
5
user.go
5
user.go
|
@ -78,11 +78,6 @@ func (user User) TokenUrl() string {
|
|||
return url
|
||||
}
|
||||
|
||||
func (user User) IndieauthMetadataUrl() string {
|
||||
url, _ := url.JoinPath(user.FullUrl(), ".well-known/oauth-authorization-server")
|
||||
return url
|
||||
}
|
||||
|
||||
func (user User) WebmentionUrl() string {
|
||||
url, _ := url.JoinPath(user.FullUrl(), "webmention/")
|
||||
return url
|
||||
|
|
Loading…
Reference in New Issue