Skip to content

Commit

Permalink
fix golang-ci lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mchtech committed Nov 11, 2024
1 parent 9b60297 commit f6e6031
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
28 changes: 10 additions & 18 deletions connector/cas/cas.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ func (c *Config) Open(id string, logger *slog.Logger) (connector.Connector, erro
}, nil
}

var (
_ connector.CallbackConnector = (*casConnector)(nil)
)
var _ connector.CallbackConnector = (*casConnector)(nil)

type casConnector struct {
client *http.Client
Expand All @@ -60,6 +58,7 @@ func (m *casConnector) LoginURL(s connector.Scopes, callbackURL, state string) (

loginURL := *m.portal
loginURL.Path += "/login"
// encode service url to context, which used in `HandleCallback`
// service = $callbackURL + $m.pathSuffix ? state=$state & context=$callbackURL + $m.pathSuffix
q := loginURL.Query()
q.Set("service", u.String()) // service = ...?state=...&context=...
Expand All @@ -69,14 +68,12 @@ func (m *casConnector) LoginURL(s connector.Scopes, callbackURL, state string) (

// HandleCallback parses the request and returns the user's identity
func (m *casConnector) HandleCallback(s connector.Scopes, r *http.Request) (connector.Identity, error) {

state := r.URL.Query().Get("state")
ticket := r.URL.Query().Get("ticket")

// service=context = $callbackURL + $m.pathSuffix
serviceURL, err := url.Parse(r.URL.Query().Get("context"))
if err != nil {
return connector.Identity{}, fmt.Errorf("failed to parse serviceURL %q: %v", r.URL.Query().Get("ext"), err)
return connector.Identity{}, fmt.Errorf("failed to parse serviceURL %q: %v", r.URL.Query().Get("context"), err)
}
// service = $callbackURL + $m.pathSuffix ? state=$state & context=$callbackURL + $m.pathSuffix
q := serviceURL.Query()
Expand All @@ -92,24 +89,20 @@ func (m *casConnector) HandleCallback(s connector.Scopes, r *http.Request) (conn
return user, nil
}

func (m *casConnector) getCasUserByTicket(ticket string, serviceURL *url.URL) (id connector.Identity, err error) {

var (
resp *cas.AuthenticationResponse
)

func (m *casConnector) getCasUserByTicket(ticket string, serviceURL *url.URL) (connector.Identity, error) {
id := connector.Identity{}
// validate ticket
validator := cas.NewServiceTicketValidator(m.client, m.portal)
if resp, err = validator.ValidateTicket(serviceURL, ticket); err != nil {
resp, err := validator.ValidateTicket(serviceURL, ticket)
if err != nil {
err = errors.Wrapf(err, "failed to validate ticket via %q with ticket %q", serviceURL, ticket)
return
return id, err
}

// fill identity
id.UserID = resp.User
id.Groups = resp.MemberOf
if len(m.mapping) == 0 {
return
return id, nil
}
if username, ok := m.mapping["username"]; ok {
id.Username = resp.Attributes.Get(username)
Expand All @@ -133,6 +126,5 @@ func (m *casConnector) getCasUserByTicket(ticket string, serviceURL *url.URL) (i
if groups, ok := m.mapping["groups"]; ok {
id.Groups = resp.Attributes[groups]
}
return

return id, nil
}
2 changes: 0 additions & 2 deletions connector/cas/cas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ mapping:
}

func TestCAS(t *testing.T) {

callback := "https://dex.example.org/dex/callback"
casURL, _ := url.Parse("https://example.org/cas")
scope := connector.Scopes{Groups: true}
Expand Down Expand Up @@ -106,7 +105,6 @@ func TestCAS(t *testing.T) {

seed := rand.NewSource(time.Now().UnixNano())
for _, tc := range cases {

ticket := fmt.Sprintf("ST-%d", seed.Int63())
state := fmt.Sprintf("%d", seed.Int63())

Expand Down

0 comments on commit f6e6031

Please sign in to comment.