4
4
"encoding/json"
5
5
"fmt"
6
6
"io"
7
+ "io/ioutil"
7
8
"net/http"
8
9
9
10
"github.com/markbates/goth"
@@ -185,24 +186,28 @@ func authorizationHeader(session *Session) (string, string) {
185
186
186
187
func userFromReader (r io.Reader , user * goth.User ) error {
187
188
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.
199
200
}{}
200
201
201
- err := json . NewDecoder ( r ). Decode ( & u )
202
+ userBytes , err := ioutil . ReadAll ( r )
202
203
if err != nil {
203
204
return err
204
205
}
205
206
207
+ if err := json .Unmarshal (userBytes , & u ); err != nil {
208
+ return err
209
+ }
210
+
206
211
user .Email = u .Email
207
212
user .Name = u .DisplayName
208
213
user .FirstName = u .FirstName
@@ -211,6 +216,10 @@ func userFromReader(r io.Reader, user *goth.User) error {
211
216
user .Location = u .OfficeLocation
212
217
user .UserID = u .ID
213
218
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
+ }
214
223
215
224
return nil
216
225
}
@@ -221,4 +230,4 @@ func scopesToStrings(scopes ...ScopeType) []string {
221
230
strs [i ] = string (scopes [i ])
222
231
}
223
232
return strs
224
- }
233
+ }
0 commit comments