mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2024-11-28 09:08:44 +02:00
40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
package providers
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/oauth2-proxy/oauth2-proxy/pkg/apis/sessions"
|
|
"github.com/oauth2-proxy/oauth2-proxy/pkg/requests"
|
|
)
|
|
|
|
// NextcloudProvider represents an Nextcloud based Identity Provider
|
|
type NextcloudProvider struct {
|
|
*ProviderData
|
|
}
|
|
|
|
var _ Provider = (*NextcloudProvider)(nil)
|
|
|
|
const nextCloudProviderName = "Nextcloud"
|
|
|
|
// NewNextcloudProvider initiates a new NextcloudProvider
|
|
func NewNextcloudProvider(p *ProviderData) *NextcloudProvider {
|
|
p.ProviderName = nextCloudProviderName
|
|
return &NextcloudProvider{ProviderData: p}
|
|
}
|
|
|
|
// GetEmailAddress returns the Account email address
|
|
func (p *NextcloudProvider) GetEmailAddress(ctx context.Context, s *sessions.SessionState) (string, error) {
|
|
json, err := requests.New(p.ValidateURL.String()).
|
|
WithContext(ctx).
|
|
WithHeaders(makeOIDCHeader(s.AccessToken)).
|
|
Do().
|
|
UnmarshalJSON()
|
|
if err != nil {
|
|
return "", fmt.Errorf("error making request: %v", err)
|
|
}
|
|
|
|
email, err := json.Get("ocs").Get("data").Get("email").String()
|
|
return email, err
|
|
}
|