From 18424a1b480309a689d64b70552978f1b6d1a4b7 Mon Sep 17 00:00:00 2001 From: Ziti-Ci Date: Tue, 18 Jul 2023 13:03:43 -0500 Subject: [PATCH] oauth updates --- controller/controller.go | 5 +- controller/oauth.go | 4 ++ controller/zrokEdgeSdk/config.go | 1 + .../share/oauth_authenticate_responses.go | 57 +++++++++++++++++++ rest_server_zrok/embedded_spec.go | 6 ++ .../share/oauth_authenticate_responses.go | 25 ++++++++ specs/zrok.yml | 4 +- 7 files changed, 98 insertions(+), 4 deletions(-) diff --git a/controller/controller.go b/controller/controller.go index 79ae24a4..d0e9dc69 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -21,9 +21,8 @@ import ( ) var ( - cfg *Config + cfg *config.Config str *store.Store - mtr *metricsAgent idb influxdb2.Client limitsAgent *limits.Agent ) @@ -72,7 +71,7 @@ func Run(inCfg *config.Config) error { api.MetadataVersionHandler = metadata.VersionHandlerFunc(versionHandler) api.ShareAccessHandler = newAccessHandler() api.ShareOauthAuthenticateHandler = newOauthHandler() - api.ShareShareHandler = newShareHandler(cfg.Limits) + api.ShareShareHandler = newShareHandler() api.ShareUnaccessHandler = newUnaccessHandler() api.ShareUnshareHandler = newUnshareHandler() api.ShareUpdateShareHandler = newUpdateShareHandler() diff --git a/controller/oauth.go b/controller/oauth.go index ded13627..d0f5736c 100644 --- a/controller/oauth.go +++ b/controller/oauth.go @@ -10,6 +10,8 @@ import ( "net/url" "strings" + "github.com/openziti/zrok/controller/oauth" + "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider" "github.com/go-openapi/runtime/middleware" @@ -24,6 +26,8 @@ func newOauthHandler() *oauthHandler { } func (h *oauthHandler) Handle(params share.OauthAuthenticateParams) middleware.Responder { + ghandle := oauth.NewGoogleOauthHandler() + return ghandle.Handle(params) awsUrl := "https:///oauth2/token" // COGNITO URL OR WHATEVER OAUTH PROVIDER URL clientId := "" // PROVIDER CLIENT ID secret := "" // PROVIDER CLIENT SECRET diff --git a/controller/zrokEdgeSdk/config.go b/controller/zrokEdgeSdk/config.go index cde825ed..06f0ec60 100644 --- a/controller/zrokEdgeSdk/config.go +++ b/controller/zrokEdgeSdk/config.go @@ -8,6 +8,7 @@ import ( "github.com/openziti/edge-api/rest_model" "github.com/openziti/zrok/model" "github.com/sirupsen/logrus" + "time" ) // TODO: Create options struct diff --git a/rest_client_zrok/share/oauth_authenticate_responses.go b/rest_client_zrok/share/oauth_authenticate_responses.go index 8d89219b..88e8f210 100644 --- a/rest_client_zrok/share/oauth_authenticate_responses.go +++ b/rest_client_zrok/share/oauth_authenticate_responses.go @@ -26,6 +26,12 @@ func (o *OauthAuthenticateReader) ReadResponse(response runtime.ClientResponse, return nil, err } return result, nil + case 500: + result := NewOauthAuthenticateInternalServerError() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result default: return nil, runtime.NewAPIError("response status code does not match any response statuses defined for this endpoint in the swagger spec", response, response.Code()) } @@ -81,3 +87,54 @@ func (o *OauthAuthenticateOK) readResponse(response runtime.ClientResponse, cons return nil } + +// NewOauthAuthenticateInternalServerError creates a OauthAuthenticateInternalServerError with default headers values +func NewOauthAuthenticateInternalServerError() *OauthAuthenticateInternalServerError { + return &OauthAuthenticateInternalServerError{} +} + +/* +OauthAuthenticateInternalServerError describes a response with status code 500, with default header values. + +internal server error +*/ +type OauthAuthenticateInternalServerError struct { +} + +// IsSuccess returns true when this oauth authenticate internal server error response has a 2xx status code +func (o *OauthAuthenticateInternalServerError) IsSuccess() bool { + return false +} + +// IsRedirect returns true when this oauth authenticate internal server error response has a 3xx status code +func (o *OauthAuthenticateInternalServerError) IsRedirect() bool { + return false +} + +// IsClientError returns true when this oauth authenticate internal server error response has a 4xx status code +func (o *OauthAuthenticateInternalServerError) IsClientError() bool { + return false +} + +// IsServerError returns true when this oauth authenticate internal server error response has a 5xx status code +func (o *OauthAuthenticateInternalServerError) IsServerError() bool { + return true +} + +// IsCode returns true when this oauth authenticate internal server error response a status code equal to that given +func (o *OauthAuthenticateInternalServerError) IsCode(code int) bool { + return code == 500 +} + +func (o *OauthAuthenticateInternalServerError) Error() string { + return fmt.Sprintf("[GET /oauth/authorize][%d] oauthAuthenticateInternalServerError ", 500) +} + +func (o *OauthAuthenticateInternalServerError) String() string { + return fmt.Sprintf("[GET /oauth/authorize][%d] oauthAuthenticateInternalServerError ", 500) +} + +func (o *OauthAuthenticateInternalServerError) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + return nil +} diff --git a/rest_server_zrok/embedded_spec.go b/rest_server_zrok/embedded_spec.go index ec5411ea..cad94033 100644 --- a/rest_server_zrok/embedded_spec.go +++ b/rest_server_zrok/embedded_spec.go @@ -725,6 +725,9 @@ func init() { "responses": { "200": { "description": "testing" + }, + "500": { + "description": "internal server error" } } } @@ -2363,6 +2366,9 @@ func init() { "responses": { "200": { "description": "testing" + }, + "500": { + "description": "internal server error" } } } diff --git a/rest_server_zrok/operations/share/oauth_authenticate_responses.go b/rest_server_zrok/operations/share/oauth_authenticate_responses.go index f0f9cc7e..027f4df0 100644 --- a/rest_server_zrok/operations/share/oauth_authenticate_responses.go +++ b/rest_server_zrok/operations/share/oauth_authenticate_responses.go @@ -35,3 +35,28 @@ func (o *OauthAuthenticateOK) WriteResponse(rw http.ResponseWriter, producer run rw.WriteHeader(200) } + +// OauthAuthenticateInternalServerErrorCode is the HTTP code returned for type OauthAuthenticateInternalServerError +const OauthAuthenticateInternalServerErrorCode int = 500 + +/* +OauthAuthenticateInternalServerError internal server error + +swagger:response oauthAuthenticateInternalServerError +*/ +type OauthAuthenticateInternalServerError struct { +} + +// NewOauthAuthenticateInternalServerError creates OauthAuthenticateInternalServerError with default headers values +func NewOauthAuthenticateInternalServerError() *OauthAuthenticateInternalServerError { + + return &OauthAuthenticateInternalServerError{} +} + +// WriteResponse to the client +func (o *OauthAuthenticateInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses + + rw.WriteHeader(500) +} diff --git a/specs/zrok.yml b/specs/zrok.yml index 9accf12d..757a31d3 100644 --- a/specs/zrok.yml +++ b/specs/zrok.yml @@ -573,6 +573,8 @@ paths: responses: 200: description: testing + 500: + description: internal server error /share: @@ -1001,7 +1003,7 @@ definitions: $ref: "#/definitions/authUser" oauthProvider: type: string - enum: [amazon] + enum: [amazon,google] oauthEmailDomains: type: array items: