From b262fa144c995d206c02aa4ed378c9d0b234c77a Mon Sep 17 00:00:00 2001 From: Darius Kazemi Date: Thu, 22 Oct 2020 12:59:19 -0700 Subject: [PATCH] Making changes per feedback --- oauth_generic.go | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/oauth_generic.go b/oauth_generic.go index b98cf59..ba8b97e 100644 --- a/oauth_generic.go +++ b/oauth_generic.go @@ -16,10 +16,10 @@ type genericOauthClient struct { InspectLocation string CallbackLocation string Scope string - MapUserID string - MapUsername string - MapDisplayName string - MapEmail string + MapUserID string + MapUsername string + MapDisplayName string + MapEmail string HttpClient HttpClient } @@ -110,27 +110,17 @@ func (c genericOauthClient) inspectOauthAccessToken(ctx context.Context, accessT // since we don't know what the JSON from the server will look like, we create a // generic interface and then map manually to values set in the config - var genericInterface interface{} + var genericInterface map[string]interface{} if err := limitedJsonUnmarshal(resp.Body, infoRequestMaxLen, &genericInterface); err != nil { return nil, err } - m := genericInterface.(map[string]interface{}) - // map each relevant field in inspectResponse to the mapped field from the config var inspectResponse InspectResponse - if (m[c.MapUserID] != nil) { - inspectResponse.UserID = m[c.MapUserID].(string) - } - if (m[c.MapUsername] != nil) { - inspectResponse.Username = m[c.MapUsername].(string) - } - if (m[c.MapDisplayName] != nil) { - inspectResponse.DisplayName = m[c.MapDisplayName].(string) - } - if (m[c.MapEmail] != nil) { - inspectResponse.Email = m[c.MapEmail].(string) - } + inspectResponse.UserID, _ = genericInterface[c.MapUserID].(string) + inspectResponse.Username, _ = genericInterface[c.MapUsername].(string) + inspectResponse.DisplayName, _ = genericInterface[c.MapDisplayName].(string) + inspectResponse.Email, _ = genericInterface[c.MapEmail].(string) return &inspectResponse, nil }