Adding slack display name to inspect response to use in user creation as per PR feedback. T710
This commit is contained in:
parent
cd5fea5ff1
commit
31e2dac118
19
oauth.go
19
oauth.go
|
@ -29,12 +29,13 @@ type TokenResponse struct {
|
||||||
|
|
||||||
// InspectResponse contains data returned when an access token is inspected.
|
// InspectResponse contains data returned when an access token is inspected.
|
||||||
type InspectResponse struct {
|
type InspectResponse struct {
|
||||||
ClientID string `json:"client_id"`
|
ClientID string `json:"client_id"`
|
||||||
UserID string `json:"user_id"`
|
UserID string `json:"user_id"`
|
||||||
ExpiresAt time.Time `json:"expires_at"`
|
ExpiresAt time.Time `json:"expires_at"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Email string `json:"email"`
|
DisplayName string `json:"-"`
|
||||||
Error string `json:"error"`
|
Email string `json:"email"`
|
||||||
|
Error string `json:"error"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// tokenRequestMaxLen is the most bytes that we'll read from the /oauth/token
|
// tokenRequestMaxLen is the most bytes that we'll read from the /oauth/token
|
||||||
|
@ -194,8 +195,12 @@ func (h oauthHandler) viewOauthCallback(w http.ResponseWriter, r *http.Request)
|
||||||
Email: zero.NewString(tokenInfo.Email, tokenInfo.Email != ""),
|
Email: zero.NewString(tokenInfo.Email, tokenInfo.Email != ""),
|
||||||
Created: time.Now().Truncate(time.Second).UTC(),
|
Created: time.Now().Truncate(time.Second).UTC(),
|
||||||
}
|
}
|
||||||
|
displayName := tokenInfo.DisplayName
|
||||||
|
if len(displayName) == 0 {
|
||||||
|
displayName = tokenInfo.Username
|
||||||
|
}
|
||||||
|
|
||||||
err = h.DB.CreateUser(h.Config, newUser, newUser.Username)
|
err = h.DB.CreateUser(h.Config, newUser, displayName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
failOAuthRequest(w, http.StatusInternalServerError, err.Error())
|
failOAuthRequest(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
|
|
|
@ -150,9 +150,10 @@ func (c slackOauthClient) inspectOauthAccessToken(ctx context.Context, accessTok
|
||||||
|
|
||||||
func (resp slackUserIdentityResponse) InspectResponse() *InspectResponse {
|
func (resp slackUserIdentityResponse) InspectResponse() *InspectResponse {
|
||||||
return &InspectResponse{
|
return &InspectResponse{
|
||||||
UserID: resp.User.ID,
|
UserID: resp.User.ID,
|
||||||
Username: slug.Make(resp.User.Name),
|
Username: slug.Make(resp.User.Name),
|
||||||
Email: resp.User.Email,
|
DisplayName: resp.User.Name,
|
||||||
|
Email: resp.User.Email,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue