Skip to content

Commit

Permalink
feat: selfservice and administrative session management (#2011)
Browse files Browse the repository at this point in the history
Closes #655
Closes #2007

Co-authored-by: hackerman <[email protected]>
  • Loading branch information
zepatrik and aeneasr authored Jan 4, 2022
1 parent 4a3e2df commit 0fe4155
Show file tree
Hide file tree
Showing 24 changed files with 3,601 additions and 91 deletions.
380 changes: 376 additions & 4 deletions docs/docs/.static/api.json

Large diffs are not rendered by default.

61 changes: 56 additions & 5 deletions docs/docs/guides/login-session.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: login-session
title: Configuring And Checking for Login Sessions
title: Configuring and Managing Login Sessions
---

import CodeFromRemote from '@theme/CodeFromRemote'
Expand All @@ -15,15 +15,15 @@ cookie or as a token, depending on the interaction type.
A session is valid for the session lifespan you specify in the Ory Kratos
config:

```yaml title="path/to/kratos/config.yml
```yaml title=path/to/kratos/config.yml
session:
lifespan: 720h # 30 days
```
Per default the session cookie has the `max-age` parameter set to the specified
session lifespan. You may disable this behavior by setting:

```yaml title="path/to/kratos/config.yml
```yaml title=path/to/kratos/config.yml
session:
cookie:
persistent: false
Expand Down Expand Up @@ -110,8 +110,6 @@ A typical session payload will look like this:
]}>
<TabItem value="nodejs">

{' '}

<CodeFromRemote
lang="js"
title="https://github.com/ory/kratos-selfservice-ui-node/blob/master/src/pkg/middleware.ts"
Expand Down Expand Up @@ -192,3 +190,56 @@ $ curl -s -X POST -H "Accept: application/json" \
}
}
```

## List Sessions using Self-Service

A user can list all sessions using the
[GET `/sessions` endpoint](../reference/api.mdx#operation/listSessions). It
returns a list of all sessions that are active and have not expired, except the
current session. This can be used to show a UI with all other sessions that are
currently active.

:::note

Make sure to include the Ory Kratos Session Cookie when calling this endpoint.
If you are calling this endpoint from a proxy or middleware, make sure to
forward the cookies sent to the proxy/middleware. If you are calling this
endpoint as an AJAX call, make sure to include credentials and configure CORS
properly.

:::

## Revoke Sessions using Self-Service

A user can revoke a specific session by calling the
[DELETE `/sessions/{id}` endpoint](../reference/api.mdx#operation/revokeSession).
This endpoint can only be used for sessions other than the current session. For
revoking the current session, use the
[self-service logout](../self-service/flows/user-logout.mdx).

A user can also revoke all other sessions using the
[DELETE `/sessions` endpoint](../reference/api.mdx#operation/revokeSessions).
This essentially loges the user out of all other sessions on any device.

Sessions that were revoked through self-service are not deleted. Instead, they
are marked as inactive. Inactive sessions are retrievable and deletable through
the administrative API.

:::note

Make sure to include the Ory Kratos Session Cookie when calling this endpoint.
If you are calling this endpoint from a proxy or middleware, make sure to
forward the cookies sent to the proxy/middleware. If you are calling this
endpoint as an AJAX call, make sure to include credentials and configure CORS
properly.

:::

## List and Revoke Sessions as an Administrator

All sessions for a specific identity can be listed using the administrative
[GET `/identities/{id}/sessions` endpoint](../reference/api.mdx#operation/adminListIdentitySessions).
There is also the administrative
[DELETE `/identities/{id}/sessions` endpoint](../reference/api.mdx#operation/adminDeleteIdentitySessions)
to delete all sessions for a specific identity. This forcefully logs the user
out of all sessions, and also deletes all session data.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.16

replace (
github.com/bradleyjkemp/cupaloy/v2 => github.com/aeneasr/cupaloy/v2 v2.6.1-0.20210924214125-3dfdd01210a3
github.com/gobuffalo/pop/v5 => github.com/gobuffalo/pop/v5 v5.3.4-0.20210608105745-bb07a373cc0e
github.com/jackc/pgconn => github.com/jackc/pgconn v1.10.1-0.20211002123621-290ee79d1e8d
github.com/knadh/koanf => github.com/aeneasr/koanf v0.14.1-0.20211230115640-aa3902b3267a
github.com/luna-duclos/instrumentedsql => github.com/ory/instrumentedsql v1.2.0
Expand Down Expand Up @@ -42,7 +41,6 @@ require (
github.com/go-swagger/go-swagger v0.26.1
github.com/gobuffalo/fizz v1.14.0
github.com/gobuffalo/httptest v1.0.2
github.com/gobuffalo/pop/v5 v5.3.4
github.com/gobuffalo/pop/v6 v6.0.1
github.com/gofrs/uuid v4.1.0+incompatible
github.com/golang-jwt/jwt/v4 v4.1.0
Expand Down
11 changes: 5 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -868,8 +868,10 @@ github.com/gobuffalo/pop v4.8.3+incompatible/go.mod h1:DwBz3SD5SsHpTZiTubcsFWcVD
github.com/gobuffalo/pop v4.8.4+incompatible/go.mod h1:DwBz3SD5SsHpTZiTubcsFWcVDpJWGsxjVjMPnkiThWg=
github.com/gobuffalo/pop v4.13.1+incompatible h1:AhbqPxNOBN/DBb2DBaiBqzOXIBQXxEYzngHHJ+ytP4g=
github.com/gobuffalo/pop v4.13.1+incompatible/go.mod h1:DwBz3SD5SsHpTZiTubcsFWcVDpJWGsxjVjMPnkiThWg=
github.com/gobuffalo/pop/v5 v5.3.4-0.20210608105745-bb07a373cc0e h1:TwTu/xo5+7Xc7PWas1NB35jwYv2ZIk+zlvA70bQnoNs=
github.com/gobuffalo/pop/v5 v5.3.4-0.20210608105745-bb07a373cc0e/go.mod h1:UiVurv2aTKC7MuR27PnMrQjAazoLr8SoC/LuTKTS/tQ=
github.com/gobuffalo/pop/v5 v5.0.11/go.mod h1:mZJHJbA3cy2V18abXYuVop2ldEJ8UZ2DK6qOekC5u5g=
github.com/gobuffalo/pop/v5 v5.2.0/go.mod h1:Hj586Cr7FoTFNmvzyNdUcajv3r0A+W+bkil4RIX/zKo=
github.com/gobuffalo/pop/v5 v5.3.1/go.mod h1:vcEDhh6cJ3WVENqJDFt/6z7zNb7lLnlN8vj3n5G9rYA=
github.com/gobuffalo/pop/v5 v5.3.3/go.mod h1:Ey1hqzDLkWQKNEfsnafaz+3P1h/TrS++W9PmpGsNxvk=
github.com/gobuffalo/pop/v6 v6.0.0/go.mod h1:5rd3OnViLhjteR8+0i/mT9Q4CzkTzCoR7tm/9mmAic4=
github.com/gobuffalo/pop/v6 v6.0.1 h1:4YhzxW4hVvf0xLW9zVkhPZFuH5VmBc4ffIIP/C++SLQ=
github.com/gobuffalo/pop/v6 v6.0.1/go.mod h1:5NO7ehmyRjRctnbMDhIqKkkg6zvdueufYltxErfp9BU=
Expand Down Expand Up @@ -1197,7 +1199,6 @@ github.com/jackc/pgtype v1.3.0/go.mod h1:b0JqxHvPmljG+HQ5IsvQ0yqeSi4nGcDTVjFoiLD
github.com/jackc/pgtype v1.3.1-0.20200510190516-8cd94a14c75a/go.mod h1:vaogEUkALtxZMCH411K+tKzNpwzCKU+AnPzBKZ+I+Po=
github.com/jackc/pgtype v1.3.1-0.20200606141011-f6355165a91c/go.mod h1:cvk9Bgu/VzJ9/lxTO5R5sf80p0DiucVtN7ZxvaC4GmQ=
github.com/jackc/pgtype v1.6.2/go.mod h1:JCULISAZBFGrHaOXIIFiyfzW5VY0GRitRr8NeJsrdig=
github.com/jackc/pgtype v1.7.0/go.mod h1:ZnHF+rMePVqDKaOfJVI4Q8IVvAQMryDlDkZnKOI75BE=
github.com/jackc/pgtype v1.8.1-0.20210724151600-32e20a603178/go.mod h1:C516IlIV9NKqfsMCXTdChteoXmwgUceqaLfjg2e3NlM=
github.com/jackc/pgtype v1.8.1 h1:9k0IXtdJXHJbyAWQgbWr1lU+MEhPXZz6RIXxfR5oxXs=
github.com/jackc/pgtype v1.8.1/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4=
Expand All @@ -1213,7 +1214,6 @@ github.com/jackc/pgx/v4 v4.6.0/go.mod h1:vPh43ZzxijXUVJ+t/EmXBtFmbFVO72cuneCT9oA
github.com/jackc/pgx/v4 v4.6.1-0.20200510190926-94ba730bb1e9/go.mod h1:t3/cdRQl6fOLDxqtlyhe9UWgfIi9R8+8v8GKV5TRA/o=
github.com/jackc/pgx/v4 v4.6.1-0.20200606145419-4e5062306904/go.mod h1:ZDaNWkt9sW1JMiNn0kdYBaLelIhw7Pg4qd+Vk6tw7Hg=
github.com/jackc/pgx/v4 v4.10.1/go.mod h1:QlrWebbs3kqEZPHCTGyxecvzG6tvIsYu+A5b1raylkA=
github.com/jackc/pgx/v4 v4.11.0/go.mod h1:i62xJgdrtVDsnL3U8ekyrQXEwGNTRoG7/8r+CIdYfcc=
github.com/jackc/pgx/v4 v4.12.1-0.20210724153913-640aa07df17c/go.mod h1:1QD0+tgSXP7iUjYm9C1NxKhny7lq6ee99u/z+IHFcgs=
github.com/jackc/pgx/v4 v4.13.0 h1:JCjhT5vmhMAf/YwBHLvrBn4OGdIQBiFG6ym8Zmdx570=
github.com/jackc/pgx/v4 v4.13.0/go.mod h1:9P4X524sErlaxj0XSGZk7s+LD0eOyu1ZDUrrpznYDF0=
Expand Down Expand Up @@ -1241,7 +1241,6 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfC
github.com/jmoiron/sqlx v0.0.0-20180614180643-0dae4fefe7c0/go.mod h1:IiEW3SEiiErVyFdH8NTuWjSifiEQKUoyK3LNqr2kCHU=
github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks=
github.com/jmoiron/sqlx v1.3.1/go.mod h1:2BljVx/86SuTyjE+aPYlHCTNvZrnJXghYGpNiXLBMCQ=
github.com/jmoiron/sqlx v1.3.3/go.mod h1:2BljVx/86SuTyjE+aPYlHCTNvZrnJXghYGpNiXLBMCQ=
github.com/jmoiron/sqlx v1.3.4 h1:wv+0IJZfL5z0uZoUjlpKgHkgaFSYD+r9CfrXjEXsO7w=
github.com/jmoiron/sqlx v1.3.4/go.mod h1:2BljVx/86SuTyjE+aPYlHCTNvZrnJXghYGpNiXLBMCQ=
github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 h1:rp+c0RAYOWj8l6qbCUTSiRLG/iKnW3K3/QfPPuSsBt4=
Expand Down Expand Up @@ -1315,7 +1314,6 @@ github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.10.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lib/pq v1.10.1/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lib/pq v1.10.4 h1:SO9z7FRPzA03QhHKJrH5BXA6HU1rS4V2nIVrrNC1iYk=
github.com/lib/pq v1.10.4/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
Expand Down Expand Up @@ -2169,6 +2167,7 @@ golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200219183655-46282727080f/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand Down
19 changes: 1 addition & 18 deletions identity/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,7 @@ type identityList []Identity
// swagger:parameters adminListIdentities
// nolint:deadcode,unused
type adminListIdentities struct {
// Items per Page
//
// This is the number of items per page.
//
// required: false
// in: query
// default: 100
// min: 1
// max: 500
PerPage int `json:"per_page"`

// Pagination Page
//
// required: false
// in: query
// default: 0
// min: 0
Page int `json:"page"`
x.PaginationParams
}

// swagger:route GET /identities v0alpha2 adminListIdentities
Expand Down
4 changes: 4 additions & 0 deletions internal/httpclient/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ docs/InlineResponse503.md
docs/JsonError.md
docs/MetadataApi.md
docs/NeedsPrivilegedSessionError.md
docs/Pagination.md
docs/RecoveryAddress.md
docs/RevokedSessions.md
docs/SelfServiceBrowserLocationChangeRequiredError.md
docs/SelfServiceError.md
docs/SelfServiceFlowExpiredError.md
Expand Down Expand Up @@ -101,7 +103,9 @@ model_inline_response_200_1.go
model_inline_response_503.go
model_json_error.go
model_needs_privileged_session_error.go
model_pagination.go
model_recovery_address.go
model_revoked_sessions.go
model_self_service_browser_location_change_required_error.go
model_self_service_error.go
model_self_service_flow_expired_error.go
Expand Down
6 changes: 6 additions & 0 deletions internal/httpclient/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Class | Method | HTTP request | Description
*V0alpha2Api* | [**AdminDeleteIdentitySessions**](docs/V0alpha2Api.md#admindeleteidentitysessions) | **Delete** /identities/{id}/sessions | Calling this endpoint irrecoverably and permanently deletes and invalidates all sessions that belong to the given Identity.
*V0alpha2Api* | [**AdminGetIdentity**](docs/V0alpha2Api.md#admingetidentity) | **Get** /identities/{id} | Get an Identity
*V0alpha2Api* | [**AdminListIdentities**](docs/V0alpha2Api.md#adminlistidentities) | **Get** /identities | List Identities
*V0alpha2Api* | [**AdminListIdentitySessions**](docs/V0alpha2Api.md#adminlistidentitysessions) | **Get** /identities/{id}/sessions | This endpoint returns all sessions that belong to the given Identity.
*V0alpha2Api* | [**AdminUpdateIdentity**](docs/V0alpha2Api.md#adminupdateidentity) | **Put** /identities/{id} | Update an Identity
*V0alpha2Api* | [**CreateSelfServiceLogoutFlowUrlForBrowsers**](docs/V0alpha2Api.md#createselfservicelogoutflowurlforbrowsers) | **Get** /self-service/logout/browser | Create a Logout URL for Browsers
*V0alpha2Api* | [**GetJsonSchema**](docs/V0alpha2Api.md#getjsonschema) | **Get** /schemas/{id} |
Expand All @@ -113,6 +114,9 @@ Class | Method | HTTP request | Description
*V0alpha2Api* | [**InitializeSelfServiceVerificationFlowForBrowsers**](docs/V0alpha2Api.md#initializeselfserviceverificationflowforbrowsers) | **Get** /self-service/verification/browser | Initialize Verification Flow for Browser Clients
*V0alpha2Api* | [**InitializeSelfServiceVerificationFlowWithoutBrowser**](docs/V0alpha2Api.md#initializeselfserviceverificationflowwithoutbrowser) | **Get** /self-service/verification/api | Initialize Verification Flow for APIs, Services, Apps, ...
*V0alpha2Api* | [**ListIdentitySchemas**](docs/V0alpha2Api.md#listidentityschemas) | **Get** /schemas |
*V0alpha2Api* | [**ListSessions**](docs/V0alpha2Api.md#listsessions) | **Get** /sessions | This endpoints returns all other active sessions that belong to the logged-in user. The current session can be retrieved by calling the &#x60;/sessions/whoami&#x60; endpoint.
*V0alpha2Api* | [**RevokeSession**](docs/V0alpha2Api.md#revokesession) | **Delete** /sessions/{id} | Calling this endpoint invalidates the specified session. The current session cannot be revoked. Session data are not deleted.
*V0alpha2Api* | [**RevokeSessions**](docs/V0alpha2Api.md#revokesessions) | **Delete** /sessions | Calling this endpoint invalidates all except the current session that belong to the logged-in user. Session data are not deleted.
*V0alpha2Api* | [**SubmitSelfServiceLoginFlow**](docs/V0alpha2Api.md#submitselfserviceloginflow) | **Post** /self-service/login | Submit a Login Flow
*V0alpha2Api* | [**SubmitSelfServiceLogoutFlow**](docs/V0alpha2Api.md#submitselfservicelogoutflow) | **Get** /self-service/logout | Complete Self-Service Logout
*V0alpha2Api* | [**SubmitSelfServiceLogoutFlowWithoutBrowser**](docs/V0alpha2Api.md#submitselfservicelogoutflowwithoutbrowser) | **Delete** /self-service/logout/api | Perform Logout for APIs, Services, Apps, ...
Expand Down Expand Up @@ -143,7 +147,9 @@ Class | Method | HTTP request | Description
- [InlineResponse503](docs/InlineResponse503.md)
- [JsonError](docs/JsonError.md)
- [NeedsPrivilegedSessionError](docs/NeedsPrivilegedSessionError.md)
- [Pagination](docs/Pagination.md)
- [RecoveryAddress](docs/RecoveryAddress.md)
- [RevokedSessions](docs/RevokedSessions.md)
- [SelfServiceBrowserLocationChangeRequiredError](docs/SelfServiceBrowserLocationChangeRequiredError.md)
- [SelfServiceError](docs/SelfServiceError.md)
- [SelfServiceFlowExpiredError](docs/SelfServiceFlowExpiredError.md)
Expand Down
Loading

0 comments on commit 0fe4155

Please sign in to comment.