| 1 |
package github |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
"fmt" |
| 6 |
"net/http" |
| 7 |
|
| 8 |
"github.com/jkroepke/openvpn-auth-oauth2/v2/internal/config" |
| 9 |
"github.com/jkroepke/openvpn-auth-oauth2/v2/internal/oauth2/providers/generic" |
| 10 |
) |
| 11 |
|
| 12 |
const Name = "github" |
| 13 |
|
| 14 |
type Provider struct { |
| 15 |
*generic.Provider |
| 16 |
|
| 17 |
httpClient *http.Client |
| 18 |
} |
| 19 |
|
| 20 |
// NewProvider returns a GitHub provider configured with the given settings. |
| 21 |
// It wraps the generic provider and adds the HTTP client for API lookups. |
| 22 |
func NewProvider(ctx context.Context, conf *config.Config, httpClient *http.Client) (Provider, error) { |
| 23 |
provider, err := generic.NewProvider(ctx, conf, httpClient) |
| 24 |
if err != nil { |
| 25 |
return Provider{}, fmt.Errorf("error creating generic provider: %w", err) |
| 26 |
} |
| 27 |
|
| 28 |
return Provider{ |
| 29 |
Provider: provider, |
| 30 |
httpClient: httpClient, |
| 31 |
}, nil |
| 32 |
} |
| 33 |
|
| 34 |
// GetName returns the provider name. |
| 35 |
func (p Provider) GetName() string { |
| 36 |
return Name |
| 37 |
} |