Revamp authenticate (#1025)
This commit is contained in:
1 parent
aa570f4e48
commit
6605b4c9f8
14 files changed
+276
-207
No files matched your search
@@ -258,8 +258,6 @@ func (s Service) DeleteAuthMethod(ctx context.Context, req *pbs.DeleteAuthMethod
|
||||
}
|
||||
|
||||
// Authenticate implements the interface pbs.AuthenticationServiceServer.
|
||||
//
|
||||
// Deprecated in favor of AuthenticateLogin
|
||||
func (s Service) Authenticate(ctx context.Context, req *pbs.AuthenticateRequest) (*pbs.AuthenticateResponse, error) {
|
||||
if err := validateAuthenticateRequest(req); err != nil {
|
||||
return nil, err
|
||||
@@ -268,8 +266,8 @@ func (s Service) Authenticate(ctx context.Context, req *pbs.AuthenticateRequest)
|
||||
if authResults.Error != nil {
|
||||
return nil, authResults.Error
|
||||
}
|
||||
creds := req.GetCredentials().GetFields()
|
||||
tok, err := s.authenticateWithRepo(ctx, authResults.Scope.GetId(), req.GetAuthMethodId(), creds[loginNameKey].GetStringValue(), creds[pwKey].GetStringValue())
|
||||
attrs := req.GetAttributes().GetFields()
|
||||
tok, err := s.authenticateWithRepo(ctx, authResults.Scope.GetId(), req.GetAuthMethodId(), attrs[loginNameKey].GetStringValue(), attrs[pwKey].GetStringValue())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -281,7 +279,7 @@ func (s Service) Authenticate(ctx context.Context, req *pbs.AuthenticateRequest)
|
||||
return &pbs.AuthenticateResponse{Item: tok, TokenType: req.GetTokenType()}, nil
|
||||
}
|
||||
|
||||
// AuthenticateLogin implements the interface pbs.AuthenticationServiceServer.
|
||||
// Deprecated: use Authenticate
|
||||
func (s Service) AuthenticateLogin(ctx context.Context, req *pbs.AuthenticateLoginRequest) (*pbs.AuthenticateLoginResponse, error) {
|
||||
if err := validateAuthenticateLoginRequest(req); err != nil {
|
||||
return nil, err
|
||||
@@ -633,7 +631,6 @@ func validateListRequest(req *pbs.ListAuthMethodsRequest) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Deprecated; remove when Authenticate is removedLogin
|
||||
func validateAuthenticateRequest(req *pbs.AuthenticateRequest) error {
|
||||
badFields := make(map[string]string)
|
||||
if strings.TrimSpace(req.GetAuthMethodId()) == "" {
|
||||
@@ -641,16 +638,23 @@ func validateAuthenticateRequest(req *pbs.AuthenticateRequest) error {
|
||||
} else if !handlers.ValidId(password.AuthMethodPrefix, req.GetAuthMethodId()) {
|
||||
badFields["auth_method_id"] = "Invalid formatted identifier."
|
||||
}
|
||||
// TODO: Update this when we enable different auth method types.
|
||||
if req.GetCredentials() == nil {
|
||||
badFields["credentials"] = "This is a required field."
|
||||
if req.GetAttributes() == nil && req.GetCredentials() != nil {
|
||||
// TODO: Eventually, remove this
|
||||
req.Attributes = req.Credentials
|
||||
}
|
||||
creds := req.GetCredentials().GetFields()
|
||||
if _, ok := creds[loginNameKey]; !ok {
|
||||
badFields["credentials.login_name"] = "This is a required field."
|
||||
if req.GetCommand() == "" {
|
||||
// TODO: Eventually, require a command. For now, fall back to "login" for backwards compat.
|
||||
req.Command = "login"
|
||||
}
|
||||
if _, ok := creds[pwKey]; !ok {
|
||||
badFields["credentials.password"] = "This is a required field."
|
||||
if req.Command != "login" {
|
||||
badFields["command"] = "Invalid command for this auth method type."
|
||||
}
|
||||
attrs := req.GetAttributes().GetFields()
|
||||
if _, ok := attrs[loginNameKey]; !ok {
|
||||
badFields["attributes.login_name"] = "This is a required field."
|
||||
}
|
||||
if _, ok := attrs[pwKey]; !ok {
|
||||
badFields["attributes.password"] = "This is a required field."
|
||||
}
|
||||
tType := strings.ToLower(strings.TrimSpace(req.GetTokenType()))
|
||||
if tType != "" && tType != "token" && tType != "cookie" {
|
||||
@@ -662,6 +666,7 @@ func validateAuthenticateRequest(req *pbs.AuthenticateRequest) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Deprecated; remove when AuthenticateLogin is removed
|
||||
func validateAuthenticateLoginRequest(req *pbs.AuthenticateLoginRequest) error {
|
||||
badFields := make(map[string]string)
|
||||
if strings.TrimSpace(req.GetAuthMethodId()) == "" {
|
||||
|
||||
Reference in new issue
Block a user