Error when generic OAuth provider doesn't return a user ID
...on the OAuth access token inspection call. This returns an error and privately (via logs) prompts the admin to add a `map_user_id` config value. Fixes #469
This commit is contained in:
parent
e983c4527f
commit
3008668a7d
|
@ -1,8 +1,20 @@
|
||||||
|
/*
|
||||||
|
* Copyright © 2020-2021 A Bunch Tell LLC and respective authors.
|
||||||
|
*
|
||||||
|
* This file is part of WriteFreely.
|
||||||
|
*
|
||||||
|
* WriteFreely is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, included
|
||||||
|
* in the LICENSE file in this source code package.
|
||||||
|
*/
|
||||||
|
|
||||||
package writefreely
|
package writefreely
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"github.com/writeas/web-core/log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -118,6 +130,10 @@ func (c genericOauthClient) inspectOauthAccessToken(ctx context.Context, accessT
|
||||||
// map each relevant field in inspectResponse to the mapped field from the config
|
// map each relevant field in inspectResponse to the mapped field from the config
|
||||||
var inspectResponse InspectResponse
|
var inspectResponse InspectResponse
|
||||||
inspectResponse.UserID, _ = genericInterface[c.MapUserID].(string)
|
inspectResponse.UserID, _ = genericInterface[c.MapUserID].(string)
|
||||||
|
if inspectResponse.UserID == "" {
|
||||||
|
log.Error("[CONFIGURATION ERROR] Generic OAuth provider returned empty UserID value (`%s`).\n Do you need to configure a different `map_user_id` value for this provider?", c.MapUserID)
|
||||||
|
return nil, fmt.Errorf("no UserID (`%s`) value returned", c.MapUserID)
|
||||||
|
}
|
||||||
inspectResponse.Username, _ = genericInterface[c.MapUsername].(string)
|
inspectResponse.Username, _ = genericInterface[c.MapUsername].(string)
|
||||||
inspectResponse.DisplayName, _ = genericInterface[c.MapDisplayName].(string)
|
inspectResponse.DisplayName, _ = genericInterface[c.MapDisplayName].(string)
|
||||||
inspectResponse.Email, _ = genericInterface[c.MapEmail].(string)
|
inspectResponse.Email, _ = genericInterface[c.MapEmail].(string)
|
||||||
|
|
Loading…
Reference in New Issue