mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2024-11-28 09:08:44 +02:00
3fa42edb73
* fix import path for v7 find ./ -name "*.go" | xargs sed -i -e 's|"github.com/oauth2-proxy/oauth2-proxy|"github.com/oauth2-proxy/oauth2-proxy/v7|' * fix module path * go mod tidy * fix installation docs * update CHANGELOG * Update CHANGELOG.md Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk> Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>
40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
package providers
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/sessions"
|
|
"github.com/oauth2-proxy/oauth2-proxy/v7/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
|
|
}
|