From 6f6159be074f175655e5b35272e7afa9ad1efff5 Mon Sep 17 00:00:00 2001 From: leoshine <71440988+leo220yuyaodog@users.noreply.github.com> Date: Fri, 22 Jul 2022 21:13:49 +0800 Subject: [PATCH] feat: add GET method of logout API (#903) --- authz/authz.go | 1 + controllers/account.go | 2 +- routers/router.go | 2 +- swagger/swagger.json | 161 ++++++++++++++++++++++++++++++++++++++++- swagger/swagger.yml | 110 +++++++++++++++++++++++++++- 5 files changed, 266 insertions(+), 10 deletions(-) diff --git a/authz/authz.go b/authz/authz.go index b5898233..aa36cbe7 100644 --- a/authz/authz.go +++ b/authz/authz.go @@ -78,6 +78,7 @@ p, *, *, POST, /api/get-email-and-phone, *, * p, *, *, POST, /api/login, *, * p, *, *, GET, /api/get-app-login, *, * p, *, *, POST, /api/logout, *, * +p, *, *, GET, /api/logout, *, * p, *, *, GET, /api/get-account, *, * p, *, *, GET, /api/userinfo, *, * p, *, *, *, /api/login/oauth, *, * diff --git a/controllers/account.go b/controllers/account.go index 271f6c53..5fb832c0 100644 --- a/controllers/account.go +++ b/controllers/account.go @@ -228,7 +228,7 @@ func (c *ApiController) Signup() { // @Tag Login API // @Description logout the current user // @Success 200 {object} controllers.Response The Response object -// @router /logout [post] +// @router /logout [get,post] func (c *ApiController) Logout() { user := c.GetSessionUsername() util.LogInfo(c.Ctx, "API: [%s] logged out", user) diff --git a/routers/router.go b/routers/router.go index bcc55cbc..b3a7c292 100644 --- a/routers/router.go +++ b/routers/router.go @@ -48,7 +48,7 @@ func initAPI() { beego.Router("/api/signup", &controllers.ApiController{}, "POST:Signup") beego.Router("/api/login", &controllers.ApiController{}, "POST:Login") beego.Router("/api/get-app-login", &controllers.ApiController{}, "GET:GetApplicationLogin") - beego.Router("/api/logout", &controllers.ApiController{}, "POST:Logout") + beego.Router("/api/logout", &controllers.ApiController{}, "GET,POST:Logout") beego.Router("/api/get-account", &controllers.ApiController{}, "GET:GetAccount") beego.Router("/api/userinfo", &controllers.ApiController{}, "GET:GetUserinfo") beego.Router("/api/unlink", &controllers.ApiController{}, "POST:Unlink") diff --git a/swagger/swagger.json b/swagger/swagger.json index 21a42ed9..301f4b40 100644 --- a/swagger/swagger.json +++ b/swagger/swagger.json @@ -2418,6 +2418,21 @@ } }, "/api/logout": { + "get": { + "tags": [ + "Login API" + ], + "description": "logout the current user", + "operationId": "ApiController.Logout", + "responses": { + "200": { + "description": "The Response object", + "schema": { + "$ref": "#/definitions/controllers.Response" + } + } + } + }, "post": { "tags": [ "Login API" @@ -3096,14 +3111,120 @@ ], "operationId": "ApiController.VerifyCaptcha" } + }, + "/api/webauthn/signin/begin": { + "get": { + "tags": [ + "Login API" + ], + "description": "WebAuthn Login Flow 1st stage", + "operationId": "ApiController.WebAuthnSigninBegin", + "parameters": [ + { + "in": "query", + "name": "owner", + "description": "owner", + "required": true, + "type": "string" + }, + { + "in": "query", + "name": "name", + "description": "name", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "The CredentialAssertion object", + "schema": { + "$ref": "#/definitions/protocol.CredentialAssertion" + } + } + } + } + }, + "/api/webauthn/signin/finish": { + "post": { + "tags": [ + "Login API" + ], + "description": "WebAuthn Login Flow 2nd stage", + "operationId": "ApiController.WebAuthnSigninBegin", + "parameters": [ + { + "in": "body", + "name": "body", + "description": "authenticator assertion Response", + "required": true, + "schema": { + "$ref": "#/definitions/protocol.CredentialAssertionResponse" + } + } + ], + "responses": { + "200": { + "description": "\"The Response object\"", + "schema": { + "$ref": "#/definitions/Response" + } + } + } + } + }, + "/api/webauthn/signup/begin": { + "get": { + "tags": [ + "User API" + ], + "description": "WebAuthn Registration Flow 1st stage", + "operationId": "ApiController.WebAuthnSignupBegin", + "responses": { + "200": { + "description": "The CredentialCreationOptions object", + "schema": { + "$ref": "#/definitions/protocol.CredentialCreation" + } + } + } + } + }, + "/api/webauthn/signup/finish": { + "post": { + "tags": [ + "User API" + ], + "description": "WebAuthn Registration Flow 2nd stage", + "operationId": "ApiController.WebAuthnSignupFinish", + "parameters": [ + { + "in": "body", + "name": "body", + "description": "authenticator attestation Response", + "required": true, + "schema": { + "$ref": "#/definitions/protocol.CredentialCreationResponse" + } + } + ], + "responses": { + "200": { + "description": "\"The Response object\"", + "schema": { + "$ref": "#/definitions/Response" + } + } + } + } } }, "definitions": { - "2127.0xc000398090.false": { + "2127.0xc000427560.false": { "title": "false", "type": "object" }, - "2161.0xc0003980c0.false": { + "2161.0xc000427590.false": { "title": "false", "type": "object" }, @@ -3221,10 +3342,10 @@ "type": "object", "properties": { "data": { - "$ref": "#/definitions/2127.0xc000398090.false" + "$ref": "#/definitions/2127.0xc000427560.false" }, "data2": { - "$ref": "#/definitions/2161.0xc0003980c0.false" + "$ref": "#/definitions/2161.0xc000427590.false" }, "msg": { "type": "string" @@ -3329,12 +3450,18 @@ "enablePassword": { "type": "boolean" }, + "enableSamlCompress": { + "type": "boolean" + }, "enableSignUp": { "type": "boolean" }, "enableSigninSession": { "type": "boolean" }, + "enableWebAuthn": { + "type": "boolean" + }, "expireInHours": { "type": "integer", "format": "int64" @@ -4507,6 +4634,12 @@ "updatedTime": { "type": "string" }, + "webauthnCredentials": { + "type": "array", + "items": { + "$ref": "#/definitions/webauthn.Credential" + } + }, "wechat": { "type": "string" }, @@ -4596,6 +4729,26 @@ } } }, + "protocol.CredentialAssertion": { + "title": "CredentialAssertion", + "type": "object" + }, + "protocol.CredentialAssertionResponse": { + "title": "CredentialAssertionResponse", + "type": "object" + }, + "protocol.CredentialCreation": { + "title": "CredentialCreation", + "type": "object" + }, + "protocol.CredentialCreationResponse": { + "title": "CredentialCreationResponse", + "type": "object" + }, + "webauthn.Credential": { + "title": "Credential", + "type": "object" + }, "xorm.Engine": { "title": "Engine", "type": "object" diff --git a/swagger/swagger.yml b/swagger/swagger.yml index 2ad6d21e..1fcc869f 100644 --- a/swagger/swagger.yml +++ b/swagger/swagger.yml @@ -1584,6 +1584,16 @@ paths: schema: $ref: '#/definitions/object.TokenError' /api/logout: + get: + tags: + - Login API + description: logout the current user + operationId: ApiController.Logout + responses: + "200": + description: The Response object + schema: + $ref: '#/definitions/controllers.Response' post: tags: - Login API @@ -2028,11 +2038,80 @@ paths: tags: - Verification API operationId: ApiController.VerifyCaptcha + /api/webauthn/signin/begin: + get: + tags: + - Login API + description: WebAuthn Login Flow 1st stage + operationId: ApiController.WebAuthnSigninBegin + parameters: + - in: query + name: owner + description: owner + required: true + type: string + - in: query + name: name + description: name + required: true + type: string + responses: + "200": + description: The CredentialAssertion object + schema: + $ref: '#/definitions/protocol.CredentialAssertion' + /api/webauthn/signin/finish: + post: + tags: + - Login API + description: WebAuthn Login Flow 2nd stage + operationId: ApiController.WebAuthnSigninBegin + parameters: + - in: body + name: body + description: authenticator assertion Response + required: true + schema: + $ref: '#/definitions/protocol.CredentialAssertionResponse' + responses: + "200": + description: '"The Response object"' + schema: + $ref: '#/definitions/Response' + /api/webauthn/signup/begin: + get: + tags: + - User API + description: WebAuthn Registration Flow 1st stage + operationId: ApiController.WebAuthnSignupBegin + responses: + "200": + description: The CredentialCreationOptions object + schema: + $ref: '#/definitions/protocol.CredentialCreation' + /api/webauthn/signup/finish: + post: + tags: + - User API + description: WebAuthn Registration Flow 2nd stage + operationId: ApiController.WebAuthnSignupFinish + parameters: + - in: body + name: body + description: authenticator attestation Response + required: true + schema: + $ref: '#/definitions/protocol.CredentialCreationResponse' + responses: + "200": + description: '"The Response object"' + schema: + $ref: '#/definitions/Response' definitions: - 2127.0xc000398090.false: + 2127.0xc000427560.false: title: "false" type: object - 2161.0xc0003980c0.false: + 2161.0xc000427590.false: title: "false" type: object Response: @@ -2113,9 +2192,9 @@ definitions: type: object properties: data: - $ref: '#/definitions/2127.0xc000398090.false' + $ref: '#/definitions/2127.0xc000427560.false' data2: - $ref: '#/definitions/2161.0xc0003980c0.false' + $ref: '#/definitions/2161.0xc000427590.false' msg: type: string name: @@ -2185,10 +2264,14 @@ definitions: type: boolean enablePassword: type: boolean + enableSamlCompress: + type: boolean enableSignUp: type: boolean enableSigninSession: type: boolean + enableWebAuthn: + type: boolean expireInHours: type: integer format: int64 @@ -2977,6 +3060,10 @@ definitions: type: string updatedTime: type: string + webauthnCredentials: + type: array + items: + $ref: '#/definitions/webauthn.Credential' wechat: type: string wecom: @@ -3035,6 +3122,21 @@ definitions: type: string url: type: string + protocol.CredentialAssertion: + title: CredentialAssertion + type: object + protocol.CredentialAssertionResponse: + title: CredentialAssertionResponse + type: object + protocol.CredentialCreation: + title: CredentialCreation + type: object + protocol.CredentialCreationResponse: + title: CredentialCreationResponse + type: object + webauthn.Credential: + title: Credential + type: object xorm.Engine: title: Engine type: object