This PR includes many fixes and refactors for oauth2 authentication and login endpoints, ie: - Invalid login returns `403` instead of `500` error - Removed the session token from console/operator `user credentials login`, `oauth flow login` and `change-password` api responses - Removed session token from localStorage - Added styles for oauth_callback page and display more descriptive errors for debugging - Success logins returns `204` instead of `200` - Removed unused swagger apis and code from both, operator and console projects - Operator `Oauth2` login flow was not validating anything, now it does Signed-off-by: Lenin Alevski <alevsk.8772@gmail.com>
58 lines
2.3 KiB
Go
58 lines
2.3 KiB
Go
// This file is part of MinIO Console Server
|
|
// Copyright (c) 2021 MinIO, Inc.
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Affero General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package auth
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/minio/console/pkg/auth/idp/oauth2"
|
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
|
xoauth2 "golang.org/x/oauth2"
|
|
)
|
|
|
|
// IdentityProviderI interface with all functions to be implemented
|
|
// by mock when testing, it should include all IdentityProvider respective api calls
|
|
// that are used within this project.
|
|
type IdentityProviderI interface {
|
|
VerifyIdentity(ctx context.Context, code, state string) (*credentials.Credentials, error)
|
|
VerifyIdentityForOperator(ctx context.Context, code, state string) (*xoauth2.Token, error)
|
|
GenerateLoginURL() string
|
|
}
|
|
|
|
// Interface implementation
|
|
//
|
|
// Define the structure of a IdentityProvider with Client inside and define the functions that are used
|
|
// during the authentication flow.
|
|
type IdentityProvider struct {
|
|
Client *oauth2.Provider
|
|
}
|
|
|
|
// VerifyIdentity will verify the user identity against the idp using the authorization code flow
|
|
func (c IdentityProvider) VerifyIdentity(ctx context.Context, code, state string) (*credentials.Credentials, error) {
|
|
return c.Client.VerifyIdentity(ctx, code, state)
|
|
}
|
|
|
|
// VerifyIdentityForOperator will verify the user identity against the idp using the authorization code flow
|
|
func (c IdentityProvider) VerifyIdentityForOperator(ctx context.Context, code, state string) (*xoauth2.Token, error) {
|
|
return c.Client.VerifyIdentityForOperator(ctx, code, state)
|
|
}
|
|
|
|
// GenerateLoginURL returns a new URL used by the user to login against the idp
|
|
func (c IdentityProvider) GenerateLoginURL() string {
|
|
return c.Client.GenerateLoginURL()
|
|
}
|