Download goalert/auth/github/provider.go from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.41 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/goalert/auth/github/provider.go
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@f5071caa249115f3b590492f1c8eb471e02aae4b/goalert/auth/github/provider.go
-
curl -L -o provider.go https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/goalert/auth/github/provider.go
1.41 kB
| package github | |
| import ( | |
| "context" | |
| "strings" | |
| "github.com/target/goalert/config" | |
| "golang.org/x/oauth2" | |
| o2Github "golang.org/x/oauth2/github" | |
| ) | |
| // Provider will respond to /auth and /callback endpoints for the purposes of GitHub OAuth2 authentication. | |
| type Provider struct { | |
| c Config | |
| } | |
| func authConfig(ctx context.Context) *oauth2.Config { | |
| cfg := config.FromContext(ctx) | |
| authURL := o2Github.Endpoint.AuthURL | |
| tokenURL := o2Github.Endpoint.TokenURL | |
| if cfg.GitHub.EnterpriseURL != "" { | |
| authURL = strings.TrimSuffix(cfg.GitHub.EnterpriseURL, "/") + "/login/oauth/authorize" | |
| tokenURL = strings.TrimSuffix(cfg.GitHub.EnterpriseURL, "/") + "/login/oauth/access_token" | |
| } | |
| scopes := []string{"read:user"} | |
| if len(cfg.GitHub.AllowedOrgs) > 0 { | |
| scopes = append(scopes, "read:org") | |
| } | |
| return &oauth2.Config{ | |
| ClientID: cfg.GitHub.ClientID, | |
| ClientSecret: cfg.GitHub.ClientSecret, | |
| Scopes: scopes, | |
| Endpoint: oauth2.Endpoint{ | |
| AuthURL: authURL, | |
| TokenURL: tokenURL, | |
| }, | |
| } | |
| } | |
| // NewProvider will validate Config and create a new Provider. If Enabled is false, validation | |
| // will be skipped. | |
| func NewProvider(ctx context.Context, c *Config) (*Provider, error) { | |
| return &Provider{ | |
| c: *c, | |
| }, nil | |
| } | |
| func containsOrg(orgs []string, name string) bool { | |
| name = strings.ToLower(name) | |
| for _, o := range orgs { | |
| if strings.ToLower(o) == name { | |
| return true | |
| } | |
| } | |
| return false | |
| } | |