refact(authmethods): Add top level token type to Authenticate (#2010)

Other parts of the system make use of a "type" field, while the
AuthenticateResponse sets a "token_type" on the response attributes
directly. Rename this field to "type", and move it up to the response
level, to be more consistent with other RPCs.

Also adds a new field to the AuthenticateRequest, "type" which will
replace the "token_type" field over time.
This commit is contained in:
Johan Brandhorst-Satzkorn authored and GitHub committed 2022-04-18 09:26:15 -04:00
1 parent bf9e7874b1
commit 80b2c9230f
15 files changed
+246 -171

No files matched your search

@@ -44,7 +44,7 @@ const (
typeField = "type"
attributesField = "attributes"
authMethodIdField = "auth_method_id"
tokenTypeField = "token_type"
tokenTypeField = "type"
isPrimaryField = "is_primary"
)
@@ -1205,7 +1205,15 @@ func (s Service) convertToAuthenticateResponse(ctx context.Context, req *pbs.Aut
if err != nil {
return nil, err
}
retAttrs.GetFields()[tokenTypeField] = structpb.NewStringValue(req.GetTokenType())
tokenType := req.GetType()
if tokenType == "" {
// Fall back to deprecated field if type is not set
tokenType = req.GetTokenType()
}
return &pbs.AuthenticateResponse{Command: req.GetCommand(), Attributes: retAttrs}, nil
return &pbs.AuthenticateResponse{
Command: req.GetCommand(),
Attributes: retAttrs,
Type: tokenType,
}, nil
}