Skip to content

Commit

Permalink
fix: annotate whoami endpoint with cookie and token
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Sep 28, 2020
1 parent 6619562 commit a8a781c
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 2 deletions.
76 changes: 75 additions & 1 deletion .schema/api.swagger.json
Expand Up @@ -402,7 +402,8 @@
"https"
],
"tags": [
"public"
"public",
"admin"
],
"operationId": "getSchema",
"parameters": [
Expand Down Expand Up @@ -545,6 +546,11 @@
},
"/self-service/login/api": {
"get": {
"security": [
{
"sessionToken": []
}
],
"description": "This endpoint initiates a login flow for API clients such as mobile devices, smart TVs, and so on.\n\nIf a valid provided session cookie or session token is provided, a 400 Bad Request error\nwill be returned unless the URL query parameter `?refresh=true` is set.\n\nTo fetch an existing login flow call `/self-service/login/flows?flow=\u003cflow_id\u003e`.\n\n:::warning\n\nYou MUST NOT use this endpoint in client-side (Single Page Apps, ReactJS, AngularJS) nor server-side (Java Server\nPages, NodeJS, PHP, Golang, ...) browser applications. Using this endpoint in these applications will make\nyou vulnerable to a variety of CSRF attacks, including CSRF login attacks.\n\nThis endpoint MUST ONLY be used in scenarios such as native mobile apps (React Native, Objective C, Swift, Java, ...).\n\n:::\n\nMore information can be found at [ORY Kratos User Login and User Registration Documentation](https://www.ory.sh/docs/next/kratos/self-service/flows/user-login-user-registration).",
"schemes": [
"http",
Expand Down Expand Up @@ -587,6 +593,11 @@
},
"/self-service/login/browser": {
"get": {
"security": [
{
"sessionToken": []
}
],
"description": "This endpoint initializes a browser-based user login flow. Once initialized, the browser will be redirected to\n`selfservice.flows.login.ui_url` with the flow ID set as the query parameter `?flow=`. If a valid user session\nexists already, the browser will be redirected to `urls.default_redirect_url` unless the query parameter\n`?refresh=true` was set.\n\nThis endpoint is NOT INTENDED for API clients and only works with browsers (Chrome, Firefox, ...).\n\nMore information can be found at [ORY Kratos User Login and User Registration Documentation](https://www.ory.sh/docs/next/kratos/self-service/flows/user-login-user-registration).",
"schemes": [
"http",
Expand Down Expand Up @@ -742,6 +753,11 @@
},
"/self-service/recovery/api": {
"get": {
"security": [
{
"sessionToken": []
}
],
"description": "This endpoint initiates a recovery flow for API clients such as mobile devices, smart TVs, and so on.\n\nIf a valid provided session cookie or session token is provided, a 400 Bad Request error.\n\nTo fetch an existing recovery flow call `/self-service/recovery/flows?flow=\u003cflow_id\u003e`.\n\n:::warning\n\nYou MUST NOT use this endpoint in client-side (Single Page Apps, ReactJS, AngularJS) nor server-side (Java Server\nPages, NodeJS, PHP, Golang, ...) browser applications. Using this endpoint in these applications will make\nyou vulnerable to a variety of CSRF attacks.\n\nThis endpoint MUST ONLY be used in scenarios such as native mobile apps (React Native, Objective C, Swift, Java, ...).\n\n:::\n\nMore information can be found at [ORY Kratos Account Recovery Documentation](../self-service/flows/account-recovery.mdx).",
"schemes": [
"http",
Expand Down Expand Up @@ -776,6 +792,11 @@
},
"/self-service/recovery/browser": {
"get": {
"security": [
{
"sessionToken": []
}
],
"description": "This endpoint initializes a browser-based account recovery flow. Once initialized, the browser will be redirected to\n`selfservice.flows.recovery.ui_url` with the flow ID set as the query parameter `?flow=`. If a valid user session\nexists, the browser is returned to the configured return URL.\n\nThis endpoint is NOT INTENDED for API clients and only works with browsers (Chrome, Firefox, ...).\n\nMore information can be found at [ORY Kratos Account Recovery Documentation](../self-service/flows/account-recovery.mdx).",
"schemes": [
"http",
Expand Down Expand Up @@ -913,6 +934,11 @@
},
"/self-service/registration/api": {
"get": {
"security": [
{
"sessionToken": []
}
],
"description": "This endpoint initiates a registration flow for API clients such as mobile devices, smart TVs, and so on.\n\nIf a valid provided session cookie or session token is provided, a 400 Bad Request error\nwill be returned unless the URL query parameter `?refresh=true` is set.\n\nTo fetch an existing registration flow call `/self-service/registration/flows?flow=\u003cflow_id\u003e`.\n\n:::warning\n\nYou MUST NOT use this endpoint in client-side (Single Page Apps, ReactJS, AngularJS) nor server-side (Java Server\nPages, NodeJS, PHP, Golang, ...) browser applications. Using this endpoint in these applications will make\nyou vulnerable to a variety of CSRF attacks.\n\nThis endpoint MUST ONLY be used in scenarios such as native mobile apps (React Native, Objective C, Swift, Java, ...).\n\n:::\n\nMore information can be found at [ORY Kratos User Login and User Registration Documentation](https://www.ory.sh/docs/next/kratos/self-service/flows/user-login-user-registration).",
"schemes": [
"http",
Expand Down Expand Up @@ -947,6 +973,11 @@
},
"/self-service/registration/browser": {
"get": {
"security": [
{
"sessionToken": []
}
],
"description": "This endpoint initializes a browser-based user registration flow. Once initialized, the browser will be redirected to\n`selfservice.flows.registration.ui_url` with the flow ID set as the query parameter `?flow=`. If a valid user session\nexists already, the browser will be redirected to `urls.default_redirect_url` unless the query parameter\n`?refresh=true` was set.\n\n:::note\n\nThis endpoint is NOT INTENDED for API clients and only works with browsers (Chrome, Firefox, ...).\n\n:::\n\nMore information can be found at [ORY Kratos User Login and User Registration Documentation](https://www.ory.sh/docs/next/kratos/self-service/flows/user-login-user-registration).",
"schemes": [
"http",
Expand Down Expand Up @@ -1091,6 +1122,11 @@
},
"/self-service/settings/api": {
"get": {
"security": [
{
"sessionToken": []
}
],
"description": "This endpoint initiates a settings flow for API clients such as mobile devices, smart TVs, and so on.\nYou must provide a valid ORY Kratos Session Token for this endpoint to respond with HTTP 200 OK.\n\nTo fetch an existing settings flow call `/self-service/settings/flows?flow=\u003cflow_id\u003e`.\n\n:::warning\n\nYou MUST NOT use this endpoint in client-side (Single Page Apps, ReactJS, AngularJS) nor server-side (Java Server\nPages, NodeJS, PHP, Golang, ...) browser applications. Using this endpoint in these applications will make\nyou vulnerable to a variety of CSRF attacks.\n\nThis endpoint MUST ONLY be used in scenarios such as native mobile apps (React Native, Objective C, Swift, Java, ...).\n\n:::\n\nMore information can be found at [ORY Kratos User Settings \u0026 Profile Management Documentation](../self-service/flows/user-settings).",
"schemes": [
"http",
Expand Down Expand Up @@ -1125,6 +1161,11 @@
},
"/self-service/settings/browser/flows": {
"get": {
"security": [
{
"sessionToken": []
}
],
"description": "This endpoint initializes a browser-based user settings flow. Once initialized, the browser will be redirected to\n`selfservice.flows.settings.ui_url` with the flow ID set as the query parameter `?flow=`. If no valid\nORY Kratos Session Cookie is included in the request, a login flow will be initialized.\n\n:::note\n\nThis endpoint is NOT INTENDED for API clients and only works with browsers (Chrome, Firefox, ...).\n\n:::\n\nMore information can be found at [ORY Kratos User Settings \u0026 Profile Management Documentation](../self-service/flows/user-settings).",
"schemes": [
"http",
Expand All @@ -1150,6 +1191,11 @@
},
"/self-service/settings/flows": {
"get": {
"security": [
{
"sessionToken": []
}
],
"description": "When accessing this endpoint through ORY Kratos' Public API you must ensure that either the ORY Kratos Session Cookie\nor the ORY Kratos Session Token are set. The public endpoint does not return 404 status codes\nbut instead 403 or 500 to improve data privacy.\n\nYou can access this endpoint without credentials when using ORY Kratos' Admin API.\n\nMore information can be found at [ORY Kratos User Settings \u0026 Profile Management Documentation](../self-service/flows/user-settings).",
"produces": [
"application/json"
Expand Down Expand Up @@ -1209,6 +1255,11 @@
},
"/self-service/settings/methods/password": {
"post": {
"security": [
{
"sessionToken": []
}
],
"description": "Use this endpoint to complete a settings flow by sending an identity's updated password. This endpoint\nbehaves differently for API and browser flows.\n\nAPI-initiated flows expect `application/json` to be sent in the body and respond with\nHTTP 200 and an application/json body with the session token on success;\nHTTP 302 redirect to a fresh settings flow if the original flow expired with the appropriate error messages set;\nHTTP 400 on form validation errors.\nHTTP 401 when the endpoint is called without a valid session token.\nHTTP 403 when `selfservice.flows.settings.privileged_session_max_age` was reached.\nImplies that the user needs to re-authenticate.\n\nBrowser flows expect `application/x-www-form-urlencoded` to be sent in the body and responds with\na HTTP 302 redirect to the post/after settings URL or the `return_to` value if it was set and if the flow succeeded;\na HTTP 302 redirect to the Settings UI URL with the flow ID containing the validation errors otherwise.\na HTTP 302 redirect to the login endpoint when `selfservice.flows.settings.privileged_session_max_age` was reached.\n\nMore information can be found at [ORY Kratos User Settings \u0026 Profile Management Documentation](../self-service/flows/user-settings).",
"consumes": [
"application/json",
Expand Down Expand Up @@ -1280,6 +1331,11 @@
},
"/self-service/settings/methods/profile": {
"post": {
"security": [
{
"sessionToken": []
}
],
"description": "Use this endpoint to complete a settings flow by sending an identity's updated traits. This endpoint\nbehaves differently for API and browser flows.\n\nAPI-initiated flows expect `application/json` to be sent in the body and respond with\nHTTP 200 and an application/json body with the session token on success;\nHTTP 302 redirect to a fresh settings flow if the original flow expired with the appropriate error messages set;\nHTTP 400 on form validation errors.\nHTTP 401 when the endpoint is called without a valid session token.\nHTTP 403 when `selfservice.flows.settings.privileged_session_max_age` was reached and a sensitive field was\nupdated (e.g. recovery email). Implies that the user needs to re-authenticate.\n\nBrowser flows expect `application/x-www-form-urlencoded` to be sent in the body and responds with\na HTTP 302 redirect to the post/after settings URL or the `return_to` value if it was set and if the flow succeeded;\na HTTP 302 redirect to the settings UI URL with the flow ID containing the validation errors otherwise.\na HTTP 302 redirect to the login endpoint when `selfservice.flows.settings.privileged_session_max_age` was reached.\n\nMore information can be found at [ORY Kratos User Settings \u0026 Profile Management Documentation](../self-service/flows/user-settings).",
"consumes": [
"application/json",
Expand Down Expand Up @@ -1554,6 +1610,11 @@
},
"/sessions/whoami": {
"get": {
"security": [
{
"sessionToken": []
}
],
"description": "Uses the HTTP Headers in the GET request to determine (e.g. by using checking the cookies) who is authenticated.\nReturns a session object in the body or 401 if the credentials are invalid or no credentials were sent.\nAdditionally when the request it successful it adds the user ID to the 'X-Kratos-Authenticated-Identity-Id' header in the response.\n\nThis endpoint is useful for reverse proxies and API Gateways.",
"produces": [
"application/json"
Expand All @@ -1567,6 +1628,19 @@
],
"summary": "Check Who the Current HTTP Session Belongs To",
"operationId": "whoami",
"parameters": [
{
"type": "string",
"name": "Cookie",
"in": "header"
},
{
"type": "string",
"description": "in: authorization",
"name": "Authorization",
"in": "query"
}
],
"responses": {
"200": {
"description": "session",
Expand Down
12 changes: 11 additions & 1 deletion session/handler.go
Expand Up @@ -118,6 +118,16 @@ func (h *Handler) revoke(w http.ResponseWriter, r *http.Request, _ httprouter.Pa
w.WriteHeader(http.StatusNoContent)
}

// nolint:deadcode,unused
// swagger:parameters whoami
type whoamiParameters struct {
// in: header
Cookie string `json:"Cookie"`

// in: authorization
Authorization string `json:"Authorization"`
}

// swagger:route GET /sessions/whoami public whoami
//
// Check Who the Current HTTP Session Belongs To
Expand All @@ -134,7 +144,7 @@ func (h *Handler) revoke(w http.ResponseWriter, r *http.Request, _ httprouter.Pa
// Schemes: http, https
//
// Security:
// - sessionToken
// sessionToken:
//
// Responses:
// 200: session
Expand Down

0 comments on commit a8a781c

Please sign in to comment.