Skip to content

Commit

Permalink
Add a route GET /settings/sessions/current
Browse files Browse the repository at this point in the history
  • Loading branch information
nono committed Oct 30, 2024
1 parent 2e4c48e commit df20ecc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
35 changes: 33 additions & 2 deletions docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ an HTML error page will appears.

```http
HTTP/1.1 307 Temporary Redirect
Location: http://alice-settings.cozy.localhost:8080
Location: http://alice-settings.cozy.localhost:8080
```


Expand Down Expand Up @@ -367,7 +367,7 @@ route is necessary to actually update the passphrase. See below.
A `"force": true` parameter can be added in the JSON to force a passphrase on a
Cozy where authentication by password is disabled and the vault is empty. It
allows to use Cozy Pass when the authentication on the Cozy is delegated via
OIDC. When forcing a password reset, you need to regenerate the
OIDC. When forcing a password reset, you need to regenerate the

* public and private keys
* encryption key
Expand Down Expand Up @@ -923,6 +923,37 @@ Content-Type: application/json
This route requires the application to have permissions on the
`io.cozy.sessions` doctype with the `GET` verb.

### GET /settings/sessions/current

This route returns information about the current session.

```
GET /settings/sessions/current HTTP/1.1
Host: cozy.example.org
Cookie: ...
Authorization: Bearer ...
```

```http
HTTP/1.1 200 OK
Content-Type: application/json
```

```json
{
"data": {
"id": "...",
"attributes": {
"last_seen": "",
"long_run": true
},
"meta": {
"rev": "..."
}
}
}
```

## OAuth 2 clients

### GET /settings/clients
Expand Down
9 changes: 9 additions & 0 deletions web/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ func (h *HTTPHandler) getSessions(c echo.Context) error {
return jsonapi.DataList(c, http.StatusOK, objs, nil)
}

func (h *HTTPHandler) getCurrentSession(c echo.Context) error {
sess, ok := middlewares.GetSession(c)
if !ok {
return jsonapi.NotFound(errors.New("no current session"))
}
return jsonapi.Data(c, http.StatusOK, &apiSession{sess}, nil)
}

func (h *HTTPHandler) listWarnings(c echo.Context) error {
inst := middlewares.GetInstance(c)

Expand Down Expand Up @@ -276,6 +284,7 @@ func (h *HTTPHandler) Register(router *echo.Group) {
router.GET("/flags", h.getFlags)

router.GET("/sessions", h.getSessions)
router.GET("/sessions/current", h.getCurrentSession)

router.GET("/clients", h.listClients)
router.DELETE("/clients/:id", h.revokeClient)
Expand Down

0 comments on commit df20ecc

Please sign in to comment.