8 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/sessions"
9 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/requests"
12// DigitalOceanProvider represents a DigitalOcean based Identity Provider
13type DigitalOceanProvider struct {
17var _ Provider = (*DigitalOceanProvider)(nil)
20 digitalOceanProviderName = "DigitalOcean"
21 digitalOceanDefaultScope = "read"
25 // Default Login URL for DigitalOcean.
26 // Pre-parsed URL of https://cloud.digitalocean.com/v1/oauth/authorize.
27 digitalOceanDefaultLoginURL = &url.URL{
29 Host: "cloud.digitalocean.com",
30 Path: "/v1/oauth/authorize",
33 // Default Redeem URL for DigitalOcean.
34 // Pre-parsed URL of https://cloud.digitalocean.com/v1/oauth/token.
35 digitalOceanDefaultRedeemURL = &url.URL{
37 Host: "cloud.digitalocean.com",
38 Path: "/v1/oauth/token",
41 // Default Profile URL for DigitalOcean.
42 // Pre-parsed URL of https://cloud.digitalocean.com/v2/account.
43 digitalOceanDefaultProfileURL = &url.URL{
45 Host: "api.digitalocean.com",
50// NewDigitalOceanProvider initiates a new DigitalOceanProvider
51func NewDigitalOceanProvider(p *ProviderData) *DigitalOceanProvider {
52 p.setProviderDefaults(providerDefaults{
53 name: digitalOceanProviderName,
54 loginURL: digitalOceanDefaultLoginURL,
55 redeemURL: digitalOceanDefaultRedeemURL,
56 profileURL: digitalOceanDefaultProfileURL,
57 validateURL: digitalOceanDefaultProfileURL,
58 scope: digitalOceanDefaultScope,
60 p.getAuthorizationHeaderFunc = makeOIDCHeader
62 return &DigitalOceanProvider{ProviderData: p}
65// GetEmailAddress returns the Account email address
66func (p *DigitalOceanProvider) GetEmailAddress(ctx context.Context, s *sessions.SessionState) (string, error) {
67 if s.AccessToken == "" {
68 return "", errors.New("missing access token")
71 json, err := requests.New(p.ProfileURL.String()).
73 WithHeaders(makeOIDCHeader(s.AccessToken)).
80 email, err := json.GetPath("account", "email").String()
87// ValidateSession validates the AccessToken
88func (p *DigitalOceanProvider) ValidateSession(ctx context.Context, s *sessions.SessionState) bool {
89 return validateToken(ctx, p, s.AccessToken, makeOIDCHeader(s.AccessToken))
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list