Skip to content

Commit 9db6207

Browse files
authored
Merge pull request #274 from danielbprice/master
azureadv2 provider should populate user.RawData
2 parents 39d29b2 + 8aacfb1 commit 9db6207

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

providers/azureadv2/azureadv2.go

+22-13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"io"
7+
"io/ioutil"
78
"net/http"
89

910
"github.com/markbates/goth"
@@ -185,24 +186,28 @@ func authorizationHeader(session *Session) (string, string) {
185186

186187
func userFromReader(r io.Reader, user *goth.User) error {
187188
u := struct {
188-
ID string `json:"id"` // The unique identifier for the user.
189-
BusinessPhone string `json:"businessPhone"` // The user's phone numbers.
190-
DisplayName string `json:"displayName"` // The name displayed in the address book for the user.
191-
FirstName string `json:"givenName"` // The first name of the user.
192-
JobTitle string `json:"jobTitle"` // The user's job title.
193-
Email string `json:"mail"` // The user's email address.
194-
MobilePhone string `json:"mobilePhone"` // The user's cellphone number.
195-
OfficeLocation string `json:"officeLocation"` // The user's physical office location.
196-
PreferredLanguage string `json:"preferredLanguage"` // The user's language of preference.
197-
LastName string `json:"surname"` // The last name of the user.
198-
UserPrincipalName string `json:"userPrincipalName"` // The user's principal name.
189+
ID string `json:"id"` // The unique identifier for the user.
190+
BusinessPhones []string `json:"businessPhones"` // The user's phone numbers.
191+
DisplayName string `json:"displayName"` // The name displayed in the address book for the user.
192+
FirstName string `json:"givenName"` // The first name of the user.
193+
JobTitle string `json:"jobTitle"` // The user's job title.
194+
Email string `json:"mail"` // The user's email address.
195+
MobilePhone string `json:"mobilePhone"` // The user's cellphone number.
196+
OfficeLocation string `json:"officeLocation"` // The user's physical office location.
197+
PreferredLanguage string `json:"preferredLanguage"` // The user's language of preference.
198+
LastName string `json:"surname"` // The last name of the user.
199+
UserPrincipalName string `json:"userPrincipalName"` // The user's principal name.
199200
}{}
200201

201-
err := json.NewDecoder(r).Decode(&u)
202+
userBytes, err := ioutil.ReadAll(r)
202203
if err != nil {
203204
return err
204205
}
205206

207+
if err := json.Unmarshal(userBytes, &u); err != nil {
208+
return err
209+
}
210+
206211
user.Email = u.Email
207212
user.Name = u.DisplayName
208213
user.FirstName = u.FirstName
@@ -211,6 +216,10 @@ func userFromReader(r io.Reader, user *goth.User) error {
211216
user.Location = u.OfficeLocation
212217
user.UserID = u.ID
213218
user.AvatarURL = graphAPIResource + fmt.Sprintf("users/%s/photo/$value", u.ID)
219+
// Make sure all of the information returned is available via RawData
220+
if err := json.Unmarshal(userBytes, &user.RawData); err != nil {
221+
return err
222+
}
214223

215224
return nil
216225
}
@@ -221,4 +230,4 @@ func scopesToStrings(scopes ...ScopeType) []string {
221230
strs[i] = string(scopes[i])
222231
}
223232
return strs
224-
}
233+
}

0 commit comments

Comments
 (0)