mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 12:30:19 +08:00
feat: support refresh token on GetOAuthToken (#1536)
This commit is contained in:
@ -172,6 +172,7 @@ func (c *ApiController) GetOAuthCode() {
|
|||||||
// @router /login/oauth/access_token [post]
|
// @router /login/oauth/access_token [post]
|
||||||
func (c *ApiController) GetOAuthToken() {
|
func (c *ApiController) GetOAuthToken() {
|
||||||
grantType := c.Input().Get("grant_type")
|
grantType := c.Input().Get("grant_type")
|
||||||
|
refreshToken := c.Input().Get("refresh_token")
|
||||||
clientId := c.Input().Get("client_id")
|
clientId := c.Input().Get("client_id")
|
||||||
clientSecret := c.Input().Get("client_secret")
|
clientSecret := c.Input().Get("client_secret")
|
||||||
code := c.Input().Get("code")
|
code := c.Input().Get("code")
|
||||||
@ -192,6 +193,7 @@ func (c *ApiController) GetOAuthToken() {
|
|||||||
clientId = tokenRequest.ClientId
|
clientId = tokenRequest.ClientId
|
||||||
clientSecret = tokenRequest.ClientSecret
|
clientSecret = tokenRequest.ClientSecret
|
||||||
grantType = tokenRequest.GrantType
|
grantType = tokenRequest.GrantType
|
||||||
|
refreshToken = tokenRequest.RefreshToken
|
||||||
code = tokenRequest.Code
|
code = tokenRequest.Code
|
||||||
verifier = tokenRequest.Verifier
|
verifier = tokenRequest.Verifier
|
||||||
scope = tokenRequest.Scope
|
scope = tokenRequest.Scope
|
||||||
@ -203,7 +205,7 @@ func (c *ApiController) GetOAuthToken() {
|
|||||||
}
|
}
|
||||||
host := c.Ctx.Request.Host
|
host := c.Ctx.Request.Host
|
||||||
|
|
||||||
c.Data["json"] = object.GetOAuthToken(grantType, clientId, clientSecret, code, verifier, scope, username, password, host, tag, avatar, c.GetAcceptLanguage())
|
c.Data["json"] = object.GetOAuthToken(grantType, clientId, clientSecret, code, verifier, scope, username, password, host, refreshToken, tag, avatar, c.GetAcceptLanguage())
|
||||||
c.SetTokenErrorHttpStatus()
|
c.SetTokenErrorHttpStatus()
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
@ -321,7 +321,7 @@ func GetOAuthCode(userId string, clientId string, responseType string, redirectU
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetOAuthToken(grantType string, clientId string, clientSecret string, code string, verifier string, scope string, username string, password string, host string, tag string, avatar string, lang string) interface{} {
|
func GetOAuthToken(grantType string, clientId string, clientSecret string, code string, verifier string, scope string, username string, password string, host string, refreshToken string, tag string, avatar string, lang string) interface{} {
|
||||||
application := GetApplicationByClientId(clientId)
|
application := GetApplicationByClientId(clientId)
|
||||||
if application == nil {
|
if application == nil {
|
||||||
return &TokenError{
|
return &TokenError{
|
||||||
@ -348,6 +348,8 @@ func GetOAuthToken(grantType string, clientId string, clientSecret string, code
|
|||||||
token, tokenError = GetPasswordToken(application, username, password, scope, host)
|
token, tokenError = GetPasswordToken(application, username, password, scope, host)
|
||||||
case "client_credentials": // Client Credentials Grant
|
case "client_credentials": // Client Credentials Grant
|
||||||
token, tokenError = GetClientCredentialsToken(application, clientSecret, scope, host)
|
token, tokenError = GetClientCredentialsToken(application, clientSecret, scope, host)
|
||||||
|
case "refresh_token":
|
||||||
|
return RefreshToken(grantType, refreshToken, scope, clientId, clientSecret, host)
|
||||||
}
|
}
|
||||||
|
|
||||||
if tag == "wechat_miniprogram" {
|
if tag == "wechat_miniprogram" {
|
||||||
|
Reference in New Issue
Block a user