Get most recent oauth token from db, rather than lookup by auth_module

This commit is contained in:
Sean Lafferty 2019-03-13 13:22:22 -04:00
parent f17307bb97
commit 3b15e110a5

View File

@ -220,15 +220,16 @@ func (proxy *DataSourceProxy) getDirector() func(req *http.Request) {
}
if proxy.ds.JsonData != nil && proxy.ds.JsonData.Get("oauthPassThru").MustBool() {
provider := proxy.ds.JsonData.Get("oauthPassThruProvider").MustString()
cmd := &m.GetAuthInfoQuery{UserId: proxy.ctx.UserId}
if err := bus.Dispatch(cmd); err != nil {
logger.Error("Error feching oauth information for user", "error", err)
}
provider := cmd.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
if !ok {
logger.Error("Failed to find oauth provider with given name", "provider", provider)
}
cmd := &m.GetAuthInfoQuery{UserId: proxy.ctx.UserId, AuthModule: provider}
if err := bus.Dispatch(cmd); err != nil {
logger.Error("Error feching oauth information for user", "error", err)
}
// TokenSource handles refreshing the token if it has expired
token, err := connect.TokenSource(proxy.ctx.Req.Context(), &oauth2.Token{