Skip to content

Commit

Permalink
update func names & add annotations
Browse files Browse the repository at this point in the history
Signed-off-by: wenhaozhou <wenhaozhou@yunify.com>
  • Loading branch information
zhou1203 committed Feb 27, 2023
1 parent d026477 commit 18edbfb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
9 changes: 7 additions & 2 deletions pkg/models/auth/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,17 @@ var (
)

// PasswordAuthenticator is an interface implemented by authenticator which take a
// username and password. provider refers to the identity provider`s name,
// if the provider is empty, authenticate from kubesphere account
// username ,password and provider. provider refers to the identity provider`s name,
// if the provider is empty, authenticate from kubesphere account. Note that implement this
// interface you should also obey the error specification defined at "k8s.io/apimachinery/pkg/api/errors.Error",
// or the server cannot handle error correctly.
type PasswordAuthenticator interface {
Authenticate(ctx context.Context, provider, username, password string) (authuser.Info, string, error)
}

// OAuthAuthenticator authenticate users by OAuth 2.0 Authorization Framework. Note that implement this
// interface you should also obey the error specification defined at "k8s.io/apimachinery/pkg/api/errors.Error",
// or the server cannot handle error correctly.
type OAuthAuthenticator interface {
Authenticate(ctx context.Context, provider string, req *http.Request) (authuser.Info, string, error)
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/models/auth/password.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ func (p *passwordAuthenticator) Authenticate(_ context.Context, provider, userna
return nil, "", IncorrectPasswordError
}
if provider != "" {
return p.providerAuthenticate(provider, username, password)
return p.authByProvider(provider, username, password)
}
return p.accountAuthenticate(username, password)
return p.authByKubeSphere(username, password)
}

// accountAuthenticate authenticate the kubesphere account
func (p *passwordAuthenticator) accountAuthenticate(username, password string) (authuser.Info, string, error) {
// authByKubeSphere authenticate by the kubesphere user
func (p *passwordAuthenticator) authByKubeSphere(username, password string) (authuser.Info, string, error) {
user, err := p.userGetter.findUser(username)
if err != nil {
// ignore not found error
Expand Down Expand Up @@ -109,7 +109,8 @@ func (p *passwordAuthenticator) accountAuthenticate(username, password string) (
return nil, "", IncorrectPasswordError
}

func (p *passwordAuthenticator) providerAuthenticate(provider, username, password string) (authuser.Info, string, error) {
// authByProvider authenticate by the third-party identity provider user
func (p *passwordAuthenticator) authByProvider(provider, username, password string) (authuser.Info, string, error) {
providerOptions, err := p.authOptions.OAuthOptions.IdentityProviderOptions(provider)
if err != nil {
klog.Error(err)
Expand Down

0 comments on commit 18edbfb

Please sign in to comment.