|
| 1 | +// This file is part of MinIO Console Server |
| 2 | +// Copyright (c) 2020 MinIO, Inc. |
| 3 | +// |
| 4 | +// This program is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU Affero General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// This program is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU Affero General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU Affero General Public License |
| 15 | +// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +// Package oauth2 contains all the necessary configurations to initialize the |
| 18 | +// idp communication using oauth2 protocol |
| 19 | +package oauth2 |
| 20 | + |
| 21 | +import ( |
| 22 | + "github.com/minio/mcs/pkg/auth/utils" |
| 23 | + "github.com/minio/minio/pkg/env" |
| 24 | +) |
| 25 | + |
| 26 | +func GetIdpURL() string { |
| 27 | + return env.Get(McsIdpURL, "") |
| 28 | +} |
| 29 | + |
| 30 | +func GetIdpClientID() string { |
| 31 | + return env.Get(McsIdpClientID, "") |
| 32 | +} |
| 33 | + |
| 34 | +func GetIdpSecret() string { |
| 35 | + return env.Get(McsIdpSecret, "") |
| 36 | +} |
| 37 | + |
| 38 | +// Public endpoint used by the identity oidcProvider when redirecting the user after identity verification |
| 39 | +func GetIdpCallbackURL() string { |
| 40 | + return env.Get(McsIdpCallbackURL, "") |
| 41 | +} |
| 42 | + |
| 43 | +func GetIdpAdminRoles() string { |
| 44 | + return env.Get(McsIdpAdminRoles, "") |
| 45 | +} |
| 46 | + |
| 47 | +func IsIdpEnabled() bool { |
| 48 | + return GetIdpURL() != "" && |
| 49 | + GetIdpClientID() != "" && |
| 50 | + GetIdpSecret() != "" && |
| 51 | + GetIdpCallbackURL() != "" |
| 52 | +} |
| 53 | + |
| 54 | +var defaultPassphraseForIdpHmac = utils.RandomCharString(64) |
| 55 | + |
| 56 | +// GetPassphraseForIdpHmac returns passphrase for the pbkdf2 function used to sign the oauth2 state parameter |
| 57 | +func getPassphraseForIdpHmac() string { |
| 58 | + return env.Get(McsIdpHmacPassphrase, defaultPassphraseForIdpHmac) |
| 59 | +} |
| 60 | + |
| 61 | +var defaultSaltForIdpHmac = utils.RandomCharString(64) |
| 62 | + |
| 63 | +// GetSaltForIdpHmac returns salt for the pbkdf2 function used to sign the oauth2 state parameter |
| 64 | +func getSaltForIdpHmac() string { |
| 65 | + return env.Get(McsIdpHmacSalt, defaultSaltForIdpHmac) |
| 66 | +} |
| 67 | + |
| 68 | +// GetSaltForIdpHmac returns the policy to be assigned to the users authenticating via an IDP |
| 69 | +func GetIDPPolicyForUser() string { |
| 70 | + return env.Get(McsIdpPolicyUser, "mcsAdmin") |
| 71 | +} |
0 commit comments