Skip to content

Commit 60c5daf

Browse files
committed
Handle empty tags for userpass login provider
The user_pass login provider had some extra logic to handle cases of machine auth. Here we cover this edge case.
1 parent ff5d488 commit 60c5daf

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

api/interface.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,15 @@ type LoginResultParams struct {
140140
serverVersion version.Number
141141
}
142142

143+
// EnsureTag should be used when a login provider needs to ensure
144+
// a login result has a tag set, particularly in cases where the
145+
// server doesn't return a user identity.
146+
func (l *LoginResultParams) EnsureTag(tag names.Tag) {
147+
if l.tag == nil {
148+
l.tag = tag
149+
}
150+
}
151+
143152
// NewLoginResultParams constructs a LoginResultParams from a Juju login response.
144153
func NewLoginResultParams(result params.LoginResult) (*LoginResultParams, error) {
145154
var controllerAccess string

api/userpass_login_provider.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ func (p *userpassLoginProvider) Login(ctx context.Context, caller base.APICaller
171171
return nil, errors.Errorf("login with discharged macaroons failed: %s", result.DischargeRequiredReason)
172172
}
173173
}
174-
175-
return NewLoginResultParams(result)
174+
loginResult, err := NewLoginResultParams(result)
175+
if err != nil {
176+
return loginResult, err
177+
}
178+
// Edge case for username/password login. Ensure the result has a tag set.
179+
// Currently no tag is returned when performing a login as a machine rather than a user.
180+
// Ideally the server would respond with the tag used as part of the request.
181+
loginResult.EnsureTag(p.tag)
182+
return loginResult, nil
176183
}

0 commit comments

Comments
 (0)