• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mindersec / minder / 13566620812

27 Feb 2025 12:41PM CUT coverage: 57.498%. First build
13566620812

Pull #5467

github

web-flow
Merge 212a43a46 into 507713f32
Pull Request #5467: build(deps): bump github.com/go-jose/go-jose/v4 from 4.0.4 to 4.0.5

18144 of 31556 relevant lines covered (57.5%)

37.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/internal/auth/github.go
1
// SPDX-FileCopyrightText: Copyright 2023 The Minder Authors
2
// SPDX-License-Identifier: Apache-2.0
3

4
// Package auth contains the authentication logic for the control plane
5
package auth
6

7
import (
8
        "context"
9
        "encoding/json"
10
        "fmt"
11
        "net/http"
12
        "net/url"
13

14
        "github.com/mindersec/minder/pkg/config/server"
15
)
16

17
// GetUserForGitHubId looks up a user in Keycloak by their GitHub ID.  This is a temporary
18
// implementation until we have a proper interface in front of IDP implementations.
19
//
20
// If the user is found, it returns their subject _in Keycloak_, suitable for use in
21
// the `sub` claim of a JWT, and in OpenFGA's user field.  Note that this function may
22
// return a user of "" with no error if no users were found matching the GitHub ID.
23
func GetUserForGitHubId(ctx context.Context, sic server.IdentityConfigWrapper, ghUser int64) (string, error) {
×
24
        // look up the user in the identity provider (keycloak-specific for now)
×
25
        q := url.Values{
×
26
                "q": {fmt.Sprintf("gh_id:%d", ghUser)},
×
27
                // TODO: add idpAlias and configuration for same
×
28
        }
×
29
        resp, err := sic.Server.Do(ctx, "GET", "admin/realms/stacklok/users", q, nil)
×
30
        if err != nil {
×
31
                return "", err
×
32
        }
×
33
        defer resp.Body.Close()
×
34
        if resp.StatusCode != http.StatusOK {
×
35
                return "", fmt.Errorf("unexpected status code %d", resp.StatusCode)
×
36
        }
×
37

38
        type kcUser struct {
×
39
                Id         string
×
40
                Username   string
×
41
                Attributes map[string][]string
×
42
        }
×
43
        users := []kcUser{}
×
44
        if err := json.NewDecoder(resp.Body).Decode(&users); err != nil {
×
45
                return "", err
×
46
        }
×
47
        if len(users) == 0 {
×
48
                // No user found, that's okay.
×
49
                return "", nil
×
50
        }
×
51
        if len(users) > 1 {
×
52
                return "", fmt.Errorf("expected 1 user, got %d", len(users))
×
53
        }
×
54
        return users[0].Id, nil
×
55
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc