10 "github.com/bitly/go-simplejson"
11 "github.com/pusher/oauth2_proxy/api"
14// AzureProvider represents an Azure based Identity Provider
15type AzureProvider struct {
20// NewAzureProvider initiates a new AzureProvider
21func NewAzureProvider(p *ProviderData) *AzureProvider {
22 p.ProviderName = "Azure"
24 if p.ProfileURL == nil || p.ProfileURL.String() == "" {
25 p.ProfileURL = &url.URL{
27 Host: "graph.windows.net",
29 RawQuery: "api-version=1.6",
32 if p.ProtectedResource == nil || p.ProtectedResource.String() == "" {
33 p.ProtectedResource = &url.URL{
35 Host: "graph.windows.net",
42 return &AzureProvider{ProviderData: p}
45// Configure defaults the AzureProvider configuration options
46func (p *AzureProvider) Configure(tenant string) {
52 if p.LoginURL == nil || p.LoginURL.String() == "" {
53 p.LoginURL = &url.URL{
55 Host: "login.microsoftonline.com",
56 Path: "/" + p.Tenant + "/oauth2/authorize"}
58 if p.RedeemURL == nil || p.RedeemURL.String() == "" {
59 p.RedeemURL = &url.URL{
61 Host: "login.microsoftonline.com",
62 Path: "/" + p.Tenant + "/oauth2/token",
67func getAzureHeader(accessToken string) http.Header {
68 header := make(http.Header)
69 header.Set("Authorization", fmt.Sprintf("Bearer %s", accessToken))
73func getEmailFromJSON(json *simplejson.Json) (string, error) {
77 email, err = json.Get("mail").String()
79 if err != nil || email == "" {
80 otherMails, otherMailsErr := json.Get("otherMails").Array()
81 if len(otherMails) > 0 {
82 email = otherMails[0].(string)
90// GetEmailAddress returns the Account email address
91func (p *AzureProvider) GetEmailAddress(s *SessionState) (string, error) {
95 if s.AccessToken == "" {
96 return "", errors.New("missing access token")
98 req, err := http.NewRequest("GET", p.ProfileURL.String(), nil)
102 req.Header = getAzureHeader(s.AccessToken)
104 json, err := api.Request(req)
110 email, err = getEmailFromJSON(json)
112 if err == nil && email != "" {
116 email, err = json.Get("userPrincipalName").String()
119 log.Printf("failed making request %s", err)
124 log.Printf("failed to get email address")
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