Skip to content
This repository has been archived by the owner on Jan 24, 2019. It is now read-only.

Interop for github provider and EmailDomains #295

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,11 @@ func (o *Options) Validate() error {

func parseProviderInfo(o *Options, msgs []string) []string {
p := &providers.ProviderData{
Scope: o.Scope,
ClientID: o.ClientID,
ClientSecret: o.ClientSecret,
ApprovalPrompt: o.ApprovalPrompt,
Scope: o.Scope,
ClientID: o.ClientID,
ClientSecret: o.ClientSecret,
ApprovalPrompt: o.ApprovalPrompt,
PreferredEmailDomains: o.EmailDomains,
}
p.LoginURL, msgs = parseURL(o.LoginURL, "login", msgs)
p.RedeemURL, msgs = parseURL(o.RedeemURL, "redeem", msgs)
Expand Down
11 changes: 10 additions & 1 deletion providers/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ func (p *GitHubProvider) hasOrgAndTeam(accessToken string) (bool, error) {
}

func (p *GitHubProvider) GetEmailAddress(s *SessionState) (string, error) {

var emails []struct {
Email string `json:"email"`
Primary bool `json:"primary"`
Expand Down Expand Up @@ -229,6 +228,16 @@ func (p *GitHubProvider) GetEmailAddress(s *SessionState) (string, error) {
return "", fmt.Errorf("%s unmarshaling %s", err, body)
}

for _, domain := range p.PreferredEmailDomains {
if domain == "*" {
break
}
for _, email := range emails {
if strings.HasSuffix(email.Email, domain) {
return email.Email, nil
}
}
}
for _, email := range emails {
if email.Primary {
return email.Email, nil
Expand Down
21 changes: 11 additions & 10 deletions providers/provider_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import (
)

type ProviderData struct {
ProviderName string
ClientID string
ClientSecret string
LoginURL *url.URL
RedeemURL *url.URL
ProfileURL *url.URL
ProtectedResource *url.URL
ValidateURL *url.URL
Scope string
ApprovalPrompt string
ProviderName string
ClientID string
ClientSecret string
LoginURL *url.URL
RedeemURL *url.URL
ProfileURL *url.URL
ProtectedResource *url.URL
ValidateURL *url.URL
Scope string
ApprovalPrompt string
PreferredEmailDomains []string
}

func (p *ProviderData) Data() *ProviderData { return p }