@@ -32,7 +32,8 @@ import (
3232)
3333
3434var (
35- errorGeneric = errors .New ("an error occurred, please try again" )
35+ errorGeneric = errors .New ("an error occurred, please try again" )
36+ errInvalidCredentials = errors .New ("invalid Credentials" )
3637)
3738
3839func registerLoginHandlers (api * operations.McsAPI ) {
@@ -61,35 +62,35 @@ func registerLoginHandlers(api *operations.McsAPI) {
6162 })
6263}
6364
64- var errInvalidCredentials = errors .New ("invalid minioCredentials" )
65-
6665// login performs a check of minioCredentials against MinIO
6766func login (credentials MCSCredentials ) (* string , error ) {
6867 // try to obtain minioCredentials,
6968 tokens , err := credentials .Get ()
7069 if err != nil {
70+ log .Println ("error authenticating user" , err )
7171 return nil , errInvalidCredentials
7272 }
7373 // if we made it here, the minioCredentials work, generate a jwt with claims
7474 jwt , err := auth .NewJWTWithClaimsForClient (& tokens , getMinIOServer ())
7575 if err != nil {
76+ log .Println ("error authenticating user" , err )
7677 return nil , errInvalidCredentials
7778 }
7879 return & jwt , nil
7980}
8081
81- func getConfiguredRegion (client MinioAdmin ) string {
82+ func getConfiguredRegionForLogin (client MinioAdmin ) ( string , error ) {
8283 location := ""
8384 configuration , err := getConfig (client , "region" )
8485 if err != nil {
8586 log .Println ("error obtaining MinIO region:" , err )
86- return location
87+ return location , errorGeneric
8788 }
8889 // region is an array of 1 element
8990 if len (configuration ) > 0 {
9091 location = configuration [0 ].Value
9192 }
92- return location
93+ return location , nil
9394}
9495
9596// getLoginResponse performs login() and serializes it to the handler's output
@@ -102,16 +103,18 @@ func getLoginResponse(lr *models.LoginRequest) (*models.LoginResponse, error) {
102103 adminClient := adminClient {client : mAdmin }
103104 // obtain the configured MinIO region
104105 // need it for user authentication
105- location := getConfiguredRegion (adminClient )
106+ location , err := getConfiguredRegionForLogin (adminClient )
107+ if err != nil {
108+ return nil , err
109+ }
106110 creds , err := newMcsCredentials (* lr .AccessKey , * lr .SecretKey , location )
107111 if err != nil {
108112 log .Println ("error login:" , err )
109- return nil , err
113+ return nil , errInvalidCredentials
110114 }
111115 credentials := mcsCredentials {minioCredentials : creds }
112116 sessionID , err := login (credentials )
113117 if err != nil {
114- log .Println ("error login:" , err )
115118 return nil , err
116119 }
117120 // serialize output
@@ -131,7 +134,8 @@ func getLoginDetailsResponse() (*models.LoginDetails, error) {
131134 // initialize new oauth2 client
132135 oauth2Client , err := oauth2 .NewOauth2ProviderClient (ctx , nil )
133136 if err != nil {
134- return nil , err
137+ log .Println ("error getting new oauth2 provider client" , err )
138+ return nil , errorGeneric
135139 }
136140 // Validate user against IDP
137141 identityProvider := & auth.IdentityProvider {Client : oauth2Client }
@@ -147,7 +151,8 @@ func getLoginDetailsResponse() (*models.LoginDetails, error) {
147151func loginOauth2Auth (ctx context.Context , provider * auth.IdentityProvider , code , state string ) (* oauth2.User , error ) {
148152 userIdentity , err := provider .VerifyIdentity (ctx , code , state )
149153 if err != nil {
150- return nil , err
154+ log .Println ("error validating user identity against idp:" , err )
155+ return nil , errorGeneric
151156 }
152157 return userIdentity , nil
153158}
@@ -166,8 +171,7 @@ func getLoginOauth2AuthResponse(lr *models.LoginOauth2AuthRequest) (*models.Logi
166171 // Validate user against IDP
167172 identity , err := loginOauth2Auth (ctx , identityProvider , * lr .Code , * lr .State )
168173 if err != nil {
169- log .Println ("error validating user identity against idp:" , err )
170- return nil , errorGeneric
174+ return nil , err
171175 }
172176 mAdmin , err := newSuperMAdminClient ()
173177 if err != nil {
@@ -179,7 +183,10 @@ func getLoginOauth2AuthResponse(lr *models.LoginOauth2AuthRequest) (*models.Logi
179183 secretKey := utils .RandomCharString (32 )
180184 // obtain the configured MinIO region
181185 // need it for user authentication
182- location := getConfiguredRegion (adminClient )
186+ location , err := getConfiguredRegionForLogin (adminClient )
187+ if err != nil {
188+ return nil , err
189+ }
183190 // create user in MinIO
184191 if _ , err := addUser (ctx , adminClient , & accessKey , & secretKey , []string {}); err != nil {
185192 log .Println ("error adding user:" , err )
@@ -207,8 +214,7 @@ func getLoginOauth2AuthResponse(lr *models.LoginOauth2AuthRequest) (*models.Logi
207214 credentials := mcsCredentials {minioCredentials : creds }
208215 jwt , err := login (credentials )
209216 if err != nil {
210- log .Println ("error login:" , err )
211- return nil , errorGeneric
217+ return nil , err
212218 }
213219 // serialize output
214220 loginResponse := & models.LoginResponse {
0 commit comments