{
    "swagger": "2.0",
    "info": {
        "description": "AuthServer OAuth2 API",
        "title": "AuthServer OAuth2",
        "contact": {},
        "version": "1.0"
    },
    "host": "127.0.0.1:10010",
    "basePath": "/",
    "paths": {
        "/api/v1/oauth/authorize/check": {
            "post": {
                "description": "Check if the authorization code request is valid and return the application info.",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "oauth2_authorization_code_inner"
                ],
                "summary": "Check the authorization code request.",
                "parameters": [
                    {
                        "description": "request",
                        "name": "request",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/oauth2.InnerAuthorizationCodeCheckRequest"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/oauth2.InnerAuthorizationCodeResponse"
                        }
                    },
                    "400": {
                        "description": "Bad Request",
                        "schema": {
                            "$ref": "#/definitions/oauth2.InnerAuthorizationCodeResponse"
                        }
                    }
                }
            }
        },
        "/api/v1/oauth/authorize/confirmation": {
            "post": {
                "description": "Approve the authorization code grant request and redirect to the redirect_uri.",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "oauth2_authorization_code_inner"
                ],
                "summary": "Approve the authorization code grant request.",
                "parameters": [
                    {
                        "description": "request",
                        "name": "request",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/oauth2.InnerAuthorizationCodeConfirmationRequest"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/oauth2.InnerAuthorizationCodeResponse"
                        }
                    },
                    "400": {
                        "description": "Bad Request",
                        "schema": {
                            "$ref": "#/definitions/oauth2.InnerAuthorizationCodeResponse"
                        }
                    }
                }
            }
        },
        "/api/v1/oauth/console/application/user-authorized": {
            "get": {
                "description": "Inner query user authorized application  for console request.",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "console_inner"
                ],
                "summary": "query user authorized application request.",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/oauth2.InnerQueryUserAuthorizedAppsResponse"
                        }
                    },
                    "400": {
                        "description": "Bad Request",
                        "schema": {
                            "$ref": "#/definitions/oauth2.InnerBasicResponse"
                        }
                    },
                    "404": {
                        "description": "Not Found",
                        "schema": {
                            "$ref": "#/definitions/oauth2.InnerBasicResponse"
                        }
                    }
                }
            }
        },
        "/api/v1/oauth/console/token": {
            "get": {
                "description": "Inner query user last token for console request.",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "console_inner"
                ],
                "summary": "query token request.",
                "parameters": [
                    {
                        "type": "integer",
                        "name": "application_id",
                        "in": "query"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/oauth2.InnerGetUserLastTokenResponse"
                        }
                    },
                    "400": {
                        "description": "Bad Request",
                        "schema": {
                            "$ref": "#/definitions/oauth2.InnerBasicResponse"
                        }
                    },
                    "404": {
                        "description": "Not Found",
                        "schema": {
                            "$ref": "#/definitions/oauth2.InnerBasicResponse"
                        }
                    }
                }
            }
        },
        "/api/v1/oauth/console/token/": {
            "post": {
                "description": "revoke token for console request.",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "console_inner"
                ],
                "summary": "console revoke token request.",
                "parameters": [
                    {
                        "description": "console revoke token request",
                        "name": "revoke",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/oauth2.ApplicationRequest"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/oauth2.InnerBasicResponse"
                        }
                    },
                    "400": {
                        "description": "Bad Request",
                        "schema": {
                            "$ref": "#/definitions/oauth2.InnerBasicResponse"
                        }
                    },
                    "404": {
                        "description": "Not Found",
                        "schema": {
                            "$ref": "#/definitions/oauth2.InnerBasicResponse"
                        }
                    }
                }
            }
        },
        "/api/v1/oauth/device/check": {
            "post": {
                "description": "Check if the user_code is valid and return the device grant request info.",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "oauth2_device_inner"
                ],
                "summary": "Check user_code for device authorization.",
                "parameters": [
                    {
                        "description": "user_code",
                        "name": "user_code",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/oauth2.InnerDeviceCheckRequest"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/oauth2.InnerDeviceCheckResponse"
                        }
                    },
                    "400": {
                        "description": "Bad Request",
                        "schema": {
                            "$ref": "#/definitions/oauth2.InnerBasicResponse"
                        }
                    }
                }
            }
        },
        "/api/v1/oauth/device/confirmation": {
            "post": {
                "description": "User can approve or deny the device authorization request.",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "oauth2_device_inner"
                ],
                "summary": "Confirm the device authorization request.",
                "parameters": [
                    {
                        "description": "confirm device authorization request",
                        "name": "confirm",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/oauth2.InnerDeviceConfirmRequest"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/oauth2.InnerBasicResponse"
                        }
                    },
                    "400": {
                        "description": "Bad Request",
                        "schema": {
                            "$ref": "#/definitions/oauth2.InnerBasicResponse"
                        }
                    },
                    "404": {
                        "description": "Can't find the device authorization request by user_code.",
                        "schema": {
                            "$ref": "#/definitions/oauth2.InnerBasicResponse"
                        }
                    }
                }
            }
        },
        "/v1/authInfo": {
            "get": {
                "description": "OAuth2 get authorization info endpoint.",
                "consumes": [
                    "application/json",
                    "application/x-www-form-urlencoded"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "oauth2_public"
                ],
                "summary": "Get authInfo endpoint.",
                "parameters": [
                    {
                        "type": "string",
                        "description": "Bearer token",
                        "name": "Authorization",
                        "in": "header",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/oauth2.AccessTokenInfo"
                        }
                    },
                    "400": {
                        "description": "Bad Request",
                        "schema": {
                            "$ref": "#/definitions/oauth2.ErrorResponse"
                        }
                    }
                }
            }
        },
        "/v1/device_authorization": {
            "post": {
                "description": "Device starts the authorization request, get the user_code, device_code and verification_uri.",
                "consumes": [
                    "application/json",
                    "application/x-www-form-urlencoded"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "oauth2_device_public"
                ],
                "summary": "Device authorization endpoint.",
                "parameters": [
                    {
                        "description": "client_id",
                        "name": "client_id",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/oauth2.DeviceAuthorizationRequest"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/oauth2.DeviceAuthorizationResponse"
                        }
                    },
                    "400": {
                        "description": "Bad Request",
                        "schema": {
                            "$ref": "#/definitions/oauth2.ErrorResponse"
                        }
                    }
                }
            }
        },
        "/v1/revoke": {
            "post": {
                "description": "OAuth2 revoke token endpoint.",
                "consumes": [
                    "application/json",
                    "application/x-www-form-urlencoded"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "oauth2_public"
                ],
                "summary": "Revoke token endpoint.",
                "parameters": [
                    {
                        "description": "token",
                        "name": "token",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/oauth2.RevokeTokenRequest"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "400": {
                        "description": "Bad Request",
                        "schema": {
                            "$ref": "#/definitions/oauth2.ErrorResponse"
                        }
                    }
                }
            }
        },
        "/v1/token": {
            "post": {
                "description": "OAuth2 token endpoint, support device code grant and refresh token grant.",
                "consumes": [
                    "application/json",
                    "application/x-www-form-urlencoded"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "oauth2_public"
                ],
                "summary": "Token endpoint.",
                "parameters": [
                    {
                        "description": "device_flow",
                        "name": "device_flow",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/oauth2.DeviceTokenRequest"
                        }
                    },
                    {
                        "description": "refresh_token",
                        "name": "refresh_token",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/oauth2.RefreshTokenRequest"
                        }
                    },
                    {
                        "description": "authorization_code",
                        "name": "authorization_code",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/oauth2.AuthorizationCodeTokenRequest"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/oauth2.TokenResponse"
                        }
                    },
                    "400": {
                        "description": "Bad Request",
                        "schema": {
                            "$ref": "#/definitions/oauth2.ErrorResponse"
                        }
                    }
                }
            }
        },
        "/v1/userinfo": {
            "get": {
                "description": "OAuth2 get userinfo endpoint.",
                "consumes": [
                    "application/json",
                    "application/x-www-form-urlencoded"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "oauth2_public"
                ],
                "summary": "Get userinfo endpoint.",
                "parameters": [
                    {
                        "type": "string",
                        "description": "Bearer token",
                        "name": "Authorization",
                        "in": "header",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/oauth2.UserInfo"
                        }
                    },
                    "400": {
                        "description": "Bad Request",
                        "schema": {
                            "$ref": "#/definitions/oauth2.ErrorResponse"
                        }
                    }
                }
            }
        }
    },
    "definitions": {
        "entity.Oauth2Scope": {
            "type": "object",
            "properties": {
                "org": {
                    "type": "string"
                },
                "project": {
                    "type": "string"
                }
            }
        },
        "oauth2.AccessTokenInfo": {
            "type": "object",
            "properties": {
                "grant_all_projects": {
                    "type": "boolean"
                },
                "grant_type": {
                    "type": "string"
                },
                "org_id": {
                    "type": "integer"
                },
                "project_ids": {
                    "type": "array",
                    "items": {
                        "type": "integer"
                    }
                },
                "scopes": {
                    "$ref": "#/definitions/entity.Oauth2Scope"
                },
                "user_email": {
                    "type": "string"
                },
                "user_id": {
                    "type": "integer"
                }
            }
        },
        "oauth2.Action": {
            "type": "string",
            "enum": [
                "approve",
                "deny"
            ],
            "x-enum-varnames": [
                "ActionApprove",
                "ActionDeny"
            ]
        },
        "oauth2.Application": {
            "type": "object",
            "properties": {
                "home_page_uri": {
                    "type": "string"
                },
                "logo_uri_dark": {
                    "type": "string"
                },
                "logo_uri_light": {
                    "type": "string"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "oauth2.ApplicationRequest": {
            "type": "object",
            "properties": {
                "application_id": {
                    "type": "integer"
                }
            }
        },
        "oauth2.AuthorizationCodeTokenRequest": {
            "type": "object",
            "properties": {
                "client_id": {
                    "type": "string"
                },
                "client_secret": {
                    "type": "string"
                },
                "code": {
                    "type": "string"
                },
                "grant_type": {
                    "type": "string"
                },
                "redirect_uri": {
                    "type": "string"
                }
            }
        },
        "oauth2.DeviceAuthorizationRequest": {
            "type": "object",
            "properties": {
                "client_id": {
                    "type": "string"
                }
            }
        },
        "oauth2.DeviceAuthorizationResponse": {
            "type": "object",
            "properties": {
                "device_code": {
                    "type": "string"
                },
                "expires_in": {
                    "type": "integer"
                },
                "interval": {
                    "type": "integer"
                },
                "user_code": {
                    "type": "string"
                },
                "verification_uri": {
                    "type": "string"
                },
                "verification_uri_complete": {
                    "type": "string"
                }
            }
        },
        "oauth2.DeviceTokenRequest": {
            "type": "object",
            "properties": {
                "client_id": {
                    "type": "string"
                },
                "device_code": {
                    "type": "string"
                },
                "grant_type": {
                    "type": "string"
                }
            }
        },
        "oauth2.ErrorResponse": {
            "type": "object",
            "properties": {
                "error": {
                    "type": "string"
                },
                "error_description": {
                    "type": "string"
                },
                "error_uri": {
                    "type": "string"
                }
            }
        },
        "oauth2.InnerAuthorizationCodeCheckRequest": {
            "type": "object",
            "properties": {
                "client_id": {
                    "type": "string"
                },
                "redirect_uri": {
                    "type": "string"
                },
                "response_type": {
                    "type": "string"
                },
                "scope": {
                    "type": "string"
                },
                "state": {
                    "type": "string"
                }
            }
        },
        "oauth2.InnerAuthorizationCodeConfirmationRequest": {
            "type": "object",
            "properties": {
                "client_id": {
                    "type": "string"
                },
                "org_id": {
                    "description": "Accept OrgId \u0026 ProjectID as a string to prevent overflow in the frontend.",
                    "type": "string"
                },
                "project_ids": {
                    "type": "array",
                    "items": {
                        "type": "string"
                    }
                },
                "redirect_uri": {
                    "type": "string"
                },
                "response_type": {
                    "type": "string"
                },
                "scope": {
                    "type": "string"
                },
                "state": {
                    "type": "string"
                }
            }
        },
        "oauth2.InnerAuthorizationCodeResponse": {
            "type": "object",
            "properties": {
                "application": {
                    "$ref": "#/definitions/oauth2.Application"
                },
                "code": {
                    "type": "integer"
                },
                "message": {
                    "type": "string"
                },
                "need_redirect": {
                    "type": "boolean"
                },
                "redirect_to": {
                    "type": "string"
                }
            }
        },
        "oauth2.InnerBasicResponse": {
            "type": "object",
            "properties": {
                "code": {
                    "type": "integer"
                },
                "message": {
                    "type": "string"
                }
            }
        },
        "oauth2.InnerDeviceCheckRequest": {
            "type": "object",
            "properties": {
                "user_code": {
                    "type": "string"
                }
            }
        },
        "oauth2.InnerDeviceCheckResponse": {
            "type": "object",
            "properties": {
                "code": {
                    "type": "integer"
                },
                "data": {
                    "type": "object",
                    "properties": {
                        "created_at": {
                            "type": "string"
                        },
                        "ip": {
                            "type": "string"
                        },
                        "user_agent": {
                            "type": "string"
                        }
                    }
                },
                "message": {
                    "type": "string"
                }
            }
        },
        "oauth2.InnerDeviceConfirmRequest": {
            "type": "object",
            "properties": {
                "action": {
                    "$ref": "#/definitions/oauth2.Action"
                },
                "org_id": {
                    "description": "Accept OrgId as a string to prevent overflow in the frontend.",
                    "type": "string"
                },
                "user_code": {
                    "type": "string"
                }
            }
        },
        "oauth2.InnerGetUserLastTokenResponse": {
            "type": "object",
            "properties": {
                "code": {
                    "type": "integer"
                },
                "message": {
                    "type": "string"
                },
                "token": {
                    "$ref": "#/definitions/oauth2.InnerQueryToken"
                }
            }
        },
        "oauth2.InnerQueryToken": {
            "type": "object",
            "properties": {
                "application_id": {
                    "type": "integer"
                },
                "application_logo_uri_dark": {
                    "type": "string"
                },
                "application_logo_uri_light": {
                    "type": "string"
                },
                "application_name": {
                    "type": "string"
                },
                "company": {
                    "type": "string"
                },
                "created_at": {
                    "type": "string"
                },
                "expire_at": {
                    "type": "string"
                },
                "grant_type": {
                    "type": "string"
                },
                "id": {
                    "type": "integer"
                },
                "org_id": {
                    "type": "string"
                },
                "scopes": {
                    "$ref": "#/definitions/entity.Oauth2Scope"
                },
                "user_email": {
                    "type": "string"
                },
                "user_id": {
                    "type": "string"
                }
            }
        },
        "oauth2.InnerQueryUserAuthorizedAppsResponse": {
            "type": "object",
            "properties": {
                "applications": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/oauth2.UserAuthorizedApp"
                    }
                },
                "code": {
                    "type": "integer"
                },
                "message": {
                    "type": "string"
                }
            }
        },
        "oauth2.RefreshTokenRequest": {
            "type": "object",
            "properties": {
                "client_id": {
                    "type": "string"
                },
                "client_secret": {
                    "type": "string"
                },
                "grant_type": {
                    "type": "string"
                },
                "refresh_token": {
                    "type": "string"
                }
            }
        },
        "oauth2.RevokeTokenRequest": {
            "type": "object",
            "properties": {
                "client_id": {
                    "type": "string"
                },
                "client_secret": {
                    "type": "string"
                },
                "token": {
                    "type": "string"
                },
                "token_type_hint": {
                    "type": "string"
                }
            }
        },
        "oauth2.TokenResponse": {
            "type": "object",
            "properties": {
                "access_token": {
                    "type": "string"
                },
                "expires_in": {
                    "type": "integer"
                },
                "refresh_token": {
                    "type": "string"
                },
                "token_type": {
                    "type": "string"
                }
            }
        },
        "oauth2.UserAuthorizedApp": {
            "type": "object",
            "properties": {
                "authorized": {
                    "type": "boolean"
                },
                "company": {
                    "type": "string"
                },
                "company_uri": {
                    "type": "string"
                },
                "description": {
                    "type": "string"
                },
                "grant_typ": {
                    "type": "string"
                },
                "home_page_uri": {
                    "type": "string"
                },
                "id": {
                    "type": "integer"
                },
                "last_used_at": {
                    "type": "string"
                },
                "logo_uri_dark": {
                    "type": "string"
                },
                "logo_uri_light": {
                    "type": "string"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "oauth2.UserInfo": {
            "type": "object",
            "properties": {
                "company name": {
                    "description": "only for tms",
                    "type": "string"
                },
                "country": {
                    "description": "only for tms",
                    "type": "string"
                },
                "email": {
                    "type": "string"
                },
                "first_name": {
                    "type": "string"
                },
                "last_name": {
                    "type": "string"
                },
                "username": {
                    "type": "string"
                }
            }
        }
    }
}