/
session_response.go
56 lines (51 loc) Β· 1.74 KB
/
session_response.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package api
import (
"github.com/gin-gonic/gin"
"github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/internal/entity"
)
// CreateSessionResponse returns the authentication response data for POST requests
// based on the session and configuration.
func CreateSessionResponse(authToken string, sess *entity.Session, conf config.ClientConfig) gin.H {
return GetSessionResponse(authToken, sess, conf)
}
// GetSessionResponse returns the authentication response data for GET requests
// based on the session and configuration.
func GetSessionResponse(authToken string, sess *entity.Session, conf config.ClientConfig) gin.H {
if authToken == "" {
return gin.H{
"status": StatusSuccess,
"session_id": sess.ID,
"expires_in": sess.ExpiresIn(),
"provider": sess.Provider().String(),
"scope": sess.Scope(),
"user": sess.User(),
"data": sess.Data(),
"config": conf,
}
} else {
return gin.H{
"status": StatusSuccess,
// TODO: "id" field is deprecated! Clients should now use "access_token" instead.
// see https://github.com/photoprism/photoprism/commit/0d2f8be522dbf0a051ae6ef78abfc9efded0082d
"id": authToken,
"session_id": sess.ID,
"access_token": authToken,
"token_type": sess.AuthTokenType(),
"expires_in": sess.ExpiresIn(),
"provider": sess.Provider().String(),
"scope": sess.Scope(),
"user": sess.User(),
"data": sess.Data(),
"config": conf,
}
}
}
// DeleteSessionResponse returns a confirmation response for DELETE requests.
func DeleteSessionResponse(id string) gin.H {
if id == "" {
return gin.H{"status": StatusDeleted}
} else {
return gin.H{"status": StatusDeleted, "session_id": id}
}
}