diff --git a/auth/pdcp/auth.go b/auth/pdcp/auth.go index 0e75cea..05fb7c9 100644 --- a/auth/pdcp/auth.go +++ b/auth/pdcp/auth.go @@ -29,7 +29,7 @@ func CheckNValidateCredentials(toolName string) { // validate by fetching user profile gotCreds, err := h.ValidateAPIKey(creds.APIKey, creds.Server, toolName) if err == nil { - gologger.Info().Msgf("You are logged in as (@%v)", gotCreds.Username) + gologger.Info().Msgf("You are logged in as (%v)", userIdentifier(gotCreds)) os.Exit(0) } gologger.Error().Msgf("Invalid API key found in file, please recheck or recreate your API key and retry.") @@ -56,7 +56,7 @@ func CheckNValidateCredentials(toolName string) { // validate by fetching user profile validatedCreds, err := h.ValidateAPIKey(apiKey, apiServer, toolName) if err == nil { - gologger.Info().Msgf("Successfully logged in as (@%v)", validatedCreds.Username) + gologger.Info().Msgf("Successfully logged in as (%v)", userIdentifier(validatedCreds)) if saveErr := h.SaveCreds(validatedCreds); saveErr != nil { gologger.Warning().Msgf("Could not save credentials to file: %s\n", saveErr) } @@ -73,3 +73,13 @@ func maskKey(key string) string { } return fmt.Sprintf("%v%v", key[:3], strings.Repeat("*", len(key)-3)) } + +// userIdentifier returns user identifier in format @username +// if username is empty, it returns email +func userIdentifier(creds *PDCPCredentials) string { + user := fmt.Sprintf("@%v", creds.Username) + if creds.Username == "" { + user = creds.Email + } + return user +} diff --git a/auth/pdcp/creds.go b/auth/pdcp/creds.go index f6f3c03..94a80ff 100644 --- a/auth/pdcp/creds.go +++ b/auth/pdcp/creds.go @@ -31,12 +31,14 @@ const ( type PDCPCredentials struct { Username string `yaml:"username"` + Email string `yaml:"email"` APIKey string `yaml:"api-key"` Server string `yaml:"server"` } type PDCPUserProfileResponse struct { UserName string `json:"name"` + Email string `json:"email"` // there are more fields but we don't need them /// below fields are added later on and not part of the response } @@ -128,10 +130,10 @@ func (p *PDCPCredHandler) ValidateAPIKey(key string, host string, toolName strin if err != nil { return nil, err } - if profile.UserName == "" { + if profile.Email == "" { return nil, fmt.Errorf("invalid response from server got %v", string(bin)) } - return &PDCPCredentials{Username: profile.UserName, APIKey: key, Server: host}, nil + return &PDCPCredentials{Username: profile.UserName, Email: profile.Email, APIKey: key, Server: host}, nil } func init() { diff --git a/auth/pdcp/creds_test.go b/auth/pdcp/creds_test.go index bf80051..cc38a7c 100644 --- a/auth/pdcp/creds_test.go +++ b/auth/pdcp/creds_test.go @@ -11,6 +11,7 @@ import ( var exampleCred = ` - username: test + email: test@projectdiscovery.io api-key: testpassword server: https://scanme.sh `