mirror of
https://github.com/openziti/zrok.git
synced 2025-01-03 04:29:19 +01:00
added security key to password changing
This commit is contained in:
parent
5861cc7d7e
commit
b6d42de92f
@ -18,7 +18,7 @@ func newChangePasswordHandler(cfg *config.Config) *changePasswordHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *changePasswordHandler) Handle(params account.ChangePasswordParams) middleware.Responder {
|
func (handler *changePasswordHandler) Handle(params account.ChangePasswordParams, principal *rest_model_zrok.Principal) middleware.Responder {
|
||||||
if params.Body == nil || params.Body.Email == "" || params.Body.OldPassword == "" || params.Body.NewPassword == "" {
|
if params.Body == nil || params.Body.Email == "" || params.Body.OldPassword == "" || params.Body.NewPassword == "" {
|
||||||
logrus.Error("missing email, old, or new password")
|
logrus.Error("missing email, old, or new password")
|
||||||
return account.NewChangePasswordUnauthorized()
|
return account.NewChangePasswordUnauthorized()
|
||||||
|
@ -30,7 +30,7 @@ type ClientOption func(*runtime.ClientOperation)
|
|||||||
|
|
||||||
// ClientService is the interface for Client methods
|
// ClientService is the interface for Client methods
|
||||||
type ClientService interface {
|
type ClientService interface {
|
||||||
ChangePassword(params *ChangePasswordParams, opts ...ClientOption) (*ChangePasswordOK, error)
|
ChangePassword(params *ChangePasswordParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ChangePasswordOK, error)
|
||||||
|
|
||||||
Invite(params *InviteParams, opts ...ClientOption) (*InviteCreated, error)
|
Invite(params *InviteParams, opts ...ClientOption) (*InviteCreated, error)
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ type ClientService interface {
|
|||||||
/*
|
/*
|
||||||
ChangePassword change password API
|
ChangePassword change password API
|
||||||
*/
|
*/
|
||||||
func (a *Client) ChangePassword(params *ChangePasswordParams, opts ...ClientOption) (*ChangePasswordOK, error) {
|
func (a *Client) ChangePassword(params *ChangePasswordParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ChangePasswordOK, error) {
|
||||||
// TODO: Validate the params before sending
|
// TODO: Validate the params before sending
|
||||||
if params == nil {
|
if params == nil {
|
||||||
params = NewChangePasswordParams()
|
params = NewChangePasswordParams()
|
||||||
@ -64,6 +64,7 @@ func (a *Client) ChangePassword(params *ChangePasswordParams, opts ...ClientOpti
|
|||||||
Schemes: []string{"http"},
|
Schemes: []string{"http"},
|
||||||
Params: params,
|
Params: params,
|
||||||
Reader: &ChangePasswordReader{formats: a.formats},
|
Reader: &ChangePasswordReader{formats: a.formats},
|
||||||
|
AuthInfo: authInfo,
|
||||||
Context: params.Context,
|
Context: params.Context,
|
||||||
Client: params.HTTPClient,
|
Client: params.HTTPClient,
|
||||||
}
|
}
|
||||||
|
@ -76,6 +76,11 @@ func init() {
|
|||||||
},
|
},
|
||||||
"/changePassword": {
|
"/changePassword": {
|
||||||
"post": {
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"key": []
|
||||||
|
}
|
||||||
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"account"
|
"account"
|
||||||
],
|
],
|
||||||
@ -1750,6 +1755,11 @@ func init() {
|
|||||||
},
|
},
|
||||||
"/changePassword": {
|
"/changePassword": {
|
||||||
"post": {
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"key": []
|
||||||
|
}
|
||||||
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"account"
|
"account"
|
||||||
],
|
],
|
||||||
|
@ -9,19 +9,21 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/go-openapi/runtime/middleware"
|
"github.com/go-openapi/runtime/middleware"
|
||||||
|
|
||||||
|
"github.com/openziti/zrok/rest_model_zrok"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ChangePasswordHandlerFunc turns a function with the right signature into a change password handler
|
// ChangePasswordHandlerFunc turns a function with the right signature into a change password handler
|
||||||
type ChangePasswordHandlerFunc func(ChangePasswordParams) middleware.Responder
|
type ChangePasswordHandlerFunc func(ChangePasswordParams, *rest_model_zrok.Principal) middleware.Responder
|
||||||
|
|
||||||
// Handle executing the request and returning a response
|
// Handle executing the request and returning a response
|
||||||
func (fn ChangePasswordHandlerFunc) Handle(params ChangePasswordParams) middleware.Responder {
|
func (fn ChangePasswordHandlerFunc) Handle(params ChangePasswordParams, principal *rest_model_zrok.Principal) middleware.Responder {
|
||||||
return fn(params)
|
return fn(params, principal)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChangePasswordHandler interface for that can handle valid change password params
|
// ChangePasswordHandler interface for that can handle valid change password params
|
||||||
type ChangePasswordHandler interface {
|
type ChangePasswordHandler interface {
|
||||||
Handle(ChangePasswordParams) middleware.Responder
|
Handle(ChangePasswordParams, *rest_model_zrok.Principal) middleware.Responder
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewChangePassword creates a new http.Handler for the change password operation
|
// NewChangePassword creates a new http.Handler for the change password operation
|
||||||
@ -45,12 +47,25 @@ func (o *ChangePassword) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
|||||||
*r = *rCtx
|
*r = *rCtx
|
||||||
}
|
}
|
||||||
var Params = NewChangePasswordParams()
|
var Params = NewChangePasswordParams()
|
||||||
|
uprinc, aCtx, err := o.Context.Authorize(r, route)
|
||||||
|
if err != nil {
|
||||||
|
o.Context.Respond(rw, r, route.Produces, route, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if aCtx != nil {
|
||||||
|
*r = *aCtx
|
||||||
|
}
|
||||||
|
var principal *rest_model_zrok.Principal
|
||||||
|
if uprinc != nil {
|
||||||
|
principal = uprinc.(*rest_model_zrok.Principal) // this is really a rest_model_zrok.Principal, I promise
|
||||||
|
}
|
||||||
|
|
||||||
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
|
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
|
||||||
o.Context.Respond(rw, r, route.Produces, route, err)
|
o.Context.Respond(rw, r, route.Produces, route, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
res := o.Handler.Handle(Params) // actually handle the request
|
res := o.Handler.Handle(Params, principal) // actually handle the request
|
||||||
o.Context.Respond(rw, r, route.Produces, route, res)
|
o.Context.Respond(rw, r, route.Produces, route, res)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ func NewZrokAPI(spec *loads.Document) *ZrokAPI {
|
|||||||
ShareAccessHandler: share.AccessHandlerFunc(func(params share.AccessParams, principal *rest_model_zrok.Principal) middleware.Responder {
|
ShareAccessHandler: share.AccessHandlerFunc(func(params share.AccessParams, principal *rest_model_zrok.Principal) middleware.Responder {
|
||||||
return middleware.NotImplemented("operation share.Access has not yet been implemented")
|
return middleware.NotImplemented("operation share.Access has not yet been implemented")
|
||||||
}),
|
}),
|
||||||
AccountChangePasswordHandler: account.ChangePasswordHandlerFunc(func(params account.ChangePasswordParams) middleware.Responder {
|
AccountChangePasswordHandler: account.ChangePasswordHandlerFunc(func(params account.ChangePasswordParams, principal *rest_model_zrok.Principal) middleware.Responder {
|
||||||
return middleware.NotImplemented("operation account.ChangePassword has not yet been implemented")
|
return middleware.NotImplemented("operation account.ChangePassword has not yet been implemented")
|
||||||
}),
|
}),
|
||||||
MetadataConfigurationHandler: metadata.ConfigurationHandlerFunc(func(params metadata.ConfigurationParams) middleware.Responder {
|
MetadataConfigurationHandler: metadata.ConfigurationHandlerFunc(func(params metadata.ConfigurationParams) middleware.Responder {
|
||||||
|
@ -107,7 +107,7 @@ class AccountApi(object):
|
|||||||
['application/zrok.v1+json']) # noqa: E501
|
['application/zrok.v1+json']) # noqa: E501
|
||||||
|
|
||||||
# Authentication setting
|
# Authentication setting
|
||||||
auth_settings = [] # noqa: E501
|
auth_settings = ['key'] # noqa: E501
|
||||||
|
|
||||||
return self.api_client.call_api(
|
return self.api_client.call_api(
|
||||||
'/changePassword', 'POST',
|
'/changePassword', 'POST',
|
||||||
|
@ -19,6 +19,8 @@ paths:
|
|||||||
post:
|
post:
|
||||||
tags:
|
tags:
|
||||||
- account
|
- account
|
||||||
|
security:
|
||||||
|
- key: []
|
||||||
operationId: changePassword
|
operationId: changePassword
|
||||||
parameters:
|
parameters:
|
||||||
- name: body
|
- name: body
|
||||||
|
@ -110,7 +110,12 @@ export function verify(options) {
|
|||||||
const changePasswordOperation = {
|
const changePasswordOperation = {
|
||||||
path: '/changePassword',
|
path: '/changePassword',
|
||||||
contentTypes: ['application/zrok.v1+json'],
|
contentTypes: ['application/zrok.v1+json'],
|
||||||
method: 'post'
|
method: 'post',
|
||||||
|
security: [
|
||||||
|
{
|
||||||
|
id: 'key'
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
const inviteOperation = {
|
const inviteOperation = {
|
||||||
|
Loading…
Reference in New Issue
Block a user