Auth: Add CLI command to create access tokens for apps #782 #808 #3943

You can now run "photoprism auth add" to create new client access tokens
that allow external applications to use the built-in REST API.

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer
2024-01-05 16:31:07 +01:00
parent d6ec8c069e
commit 713593da4e
117 changed files with 2528 additions and 938 deletions

View File

@@ -13,7 +13,7 @@ func TestUpdateLabel(t *testing.T) {
t.Run("successful request", func(t *testing.T) {
app, router, _ := NewApiTest()
UpdateLabel(router)
r := PerformRequestWithBody(app, "PUT", "/api/v1/labels/lt9k3pw1wowuy3c7", `{"Name": "Updated01", "Priority": 2}`)
r := PerformRequestWithBody(app, "PUT", "/api/v1/labels/ls6sg6b1wowuy3c7", `{"Name": "Updated01", "Priority": 2}`)
val := gjson.Get(r.Body.String(), "Name")
assert.Equal(t, "Updated01", val.String())
val2 := gjson.Get(r.Body.String(), "CustomSlug")
@@ -24,7 +24,7 @@ func TestUpdateLabel(t *testing.T) {
t.Run("invalid request", func(t *testing.T) {
app, router, _ := NewApiTest()
UpdateLabel(router)
r := PerformRequestWithBody(app, "PUT", "/api/v1/labels/lt9k3pw1wowuy3c7", `{"Name": 123, "Priority": 4, "Uncertainty": 80}`)
r := PerformRequestWithBody(app, "PUT", "/api/v1/labels/ls6sg6b1wowuy3c7", `{"Name": 123, "Priority": 4, "Uncertainty": 80}`)
assert.Equal(t, http.StatusBadRequest, r.Code)
})
@@ -57,7 +57,7 @@ func TestLikeLabel(t *testing.T) {
val := gjson.Get(r2.Body.String(), `#(Slug=="like-label").Favorite`)
assert.Equal(t, "false", val.String())
r := PerformRequest(app, "POST", "/api/v1/labels/lt9k3pw1wowuy3c9/like")
r := PerformRequest(app, "POST", "/api/v1/labels/ls6sg6b1wowuy3c9/like")
t.Log(r.Body.String())
assert.Equal(t, http.StatusOK, r.Code)
@@ -69,7 +69,7 @@ func TestLikeLabel(t *testing.T) {
t.Run("like existing label with prio < 0", func(t *testing.T) {
app, router, _ := NewApiTest()
LikeLabel(router)
r := PerformRequest(app, "POST", "/api/v1/labels/lt9k3pw1wowuy311/like")
r := PerformRequest(app, "POST", "/api/v1/labels/ls6sg6b1wowuy311/like")
t.Log(r.Body.String())
assert.Equal(t, http.StatusOK, r.Code)
})
@@ -97,7 +97,7 @@ func TestDislikeLabel(t *testing.T) {
val := gjson.Get(r2.Body.String(), `#(Slug=="landscape").Favorite`)
assert.Equal(t, "true", val.String())
r := PerformRequest(app, "DELETE", "/api/v1/labels/lt9k3pw1wowuy3c2/like")
r := PerformRequest(app, "DELETE", "/api/v1/labels/ls6sg6b1wowuy3c2/like")
assert.Equal(t, http.StatusOK, r.Code)
r3 := PerformRequest(app, "GET", "/api/v1/labels?count=3&q=landscape")
@@ -108,7 +108,7 @@ func TestDislikeLabel(t *testing.T) {
t.Run("dislike existing label with prio < 0", func(t *testing.T) {
app, router, _ := NewApiTest()
DislikeLabel(router)
r := PerformRequest(app, "DELETE", "/api/v1/labels/lt9k3pw1wowuy312/like")
r := PerformRequest(app, "DELETE", "/api/v1/labels/ls6sg6b1wowuy312/like")
assert.Equal(t, http.StatusOK, r.Code)
})
}