mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Rename dispatched commands to make them easy to grok
This commit is contained in:
parent
be6e76ee35
commit
b696492891
@ -320,13 +320,13 @@ func checkWhiteList(c *m.ReqContext, host string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func addOAuthPassThruAuth(c *m.ReqContext, req *http.Request) {
|
func addOAuthPassThruAuth(c *m.ReqContext, req *http.Request) {
|
||||||
cmd := &m.GetAuthInfoQuery{UserId: c.UserId}
|
authInfoQuery := &m.GetAuthInfoQuery{UserId: c.UserId}
|
||||||
if err := bus.Dispatch(cmd); err != nil {
|
if err := bus.Dispatch(authInfoQuery); err != nil {
|
||||||
logger.Error("Error feching oauth information for user", "error", err)
|
logger.Error("Error feching oauth information for user", "error", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
provider := cmd.Result.AuthModule
|
provider := authInfoQuery.Result.AuthModule
|
||||||
connect, ok := social.SocialMap[strings.TrimPrefix(provider, "oauth_")] // The socialMap keys don't have "oauth_" prefix, but everywhere else in the system does
|
connect, ok := social.SocialMap[strings.TrimPrefix(provider, "oauth_")] // The socialMap keys don't have "oauth_" prefix, but everywhere else in the system does
|
||||||
if !ok {
|
if !ok {
|
||||||
logger.Error("Failed to find oauth provider with given name", "provider", provider)
|
logger.Error("Failed to find oauth provider with given name", "provider", provider)
|
||||||
@ -335,25 +335,25 @@ func addOAuthPassThruAuth(c *m.ReqContext, req *http.Request) {
|
|||||||
|
|
||||||
// TokenSource handles refreshing the token if it has expired
|
// TokenSource handles refreshing the token if it has expired
|
||||||
token, err := connect.TokenSource(c.Req.Context(), &oauth2.Token{
|
token, err := connect.TokenSource(c.Req.Context(), &oauth2.Token{
|
||||||
AccessToken: cmd.Result.OAuthAccessToken,
|
AccessToken: authInfoQuery.Result.OAuthAccessToken,
|
||||||
Expiry: cmd.Result.OAuthExpiry,
|
Expiry: authInfoQuery.Result.OAuthExpiry,
|
||||||
RefreshToken: cmd.Result.OAuthRefreshToken,
|
RefreshToken: authInfoQuery.Result.OAuthRefreshToken,
|
||||||
TokenType: cmd.Result.OAuthTokenType,
|
TokenType: authInfoQuery.Result.OAuthTokenType,
|
||||||
}).Token()
|
}).Token()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("Failed to retrieve access token from oauth provider", "provider", cmd.Result.AuthModule)
|
logger.Error("Failed to retrieve access token from oauth provider", "provider", authInfoQuery.Result.AuthModule)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the tokens are not the same, update the entry in the DB
|
// If the tokens are not the same, update the entry in the DB
|
||||||
if token.AccessToken != cmd.Result.OAuthAccessToken {
|
if token.AccessToken != authInfoQuery.Result.OAuthAccessToken {
|
||||||
cmd2 := &m.UpdateAuthInfoCommand{
|
updateAuthCommand := &m.UpdateAuthInfoCommand{
|
||||||
UserId: cmd.Result.Id,
|
UserId: authInfoQuery.Result.Id,
|
||||||
AuthModule: cmd.Result.AuthModule,
|
AuthModule: authInfoQuery.Result.AuthModule,
|
||||||
AuthId: cmd.Result.AuthId,
|
AuthId: authInfoQuery.Result.AuthId,
|
||||||
OAuthToken: token,
|
OAuthToken: token,
|
||||||
}
|
}
|
||||||
if err := bus.Dispatch(cmd2); err != nil {
|
if err := bus.Dispatch(updateAuthCommand); err != nil {
|
||||||
logger.Error("Failed to update access token during token refresh", "error", err)
|
logger.Error("Failed to update access token during token refresh", "error", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user