mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 02:35:49 +08:00
style: golint (#988)
This commit is contained in:
parent
4dd67a8dcb
commit
79119760f2
@ -18,7 +18,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"sort"
|
"sort"
|
||||||
@ -80,7 +80,7 @@ func (captcha *AliyunCaptchaProvider) VerifyCaptcha(token, clientSecret string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
@ -58,7 +58,7 @@ func (captcha *GEETESTCaptchaProvider) VerifyCaptcha(token, clientSecret string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ package captcha
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
@ -43,7 +43,7 @@ func (captcha *HCaptchaProvider) VerifyCaptcha(token, clientSecret string) (bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ package captcha
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
@ -43,7 +43,7 @@ func (captcha *ReCaptchaProvider) VerifyCaptcha(token, clientSecret string) (boo
|
|||||||
}
|
}
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -274,6 +274,7 @@ func (c *ApiController) GetAccount() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUserinfo
|
||||||
// UserInfo
|
// UserInfo
|
||||||
// @Title UserInfo
|
// @Title UserInfo
|
||||||
// @Tag Account API
|
// @Tag Account API
|
||||||
|
@ -118,7 +118,7 @@ func (c *ApiController) HandleLoggedIn(application *object.Application, user *ob
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
resp = wrapErrorResponse(fmt.Errorf("Unknown response type: %s", form.Type))
|
resp = wrapErrorResponse(fmt.Errorf("unknown response type: %s", form.Type))
|
||||||
}
|
}
|
||||||
|
|
||||||
// if user did not check auto signin
|
// if user did not check auto signin
|
||||||
|
@ -23,11 +23,13 @@ import (
|
|||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ApiController
|
||||||
// controller for handlers under /api uri
|
// controller for handlers under /api uri
|
||||||
type ApiController struct {
|
type ApiController struct {
|
||||||
beego.Controller
|
beego.Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RootController
|
||||||
// controller for handlers directly under / (root)
|
// controller for handlers directly under / (root)
|
||||||
type RootController struct {
|
type RootController struct {
|
||||||
ApiController
|
ApiController
|
||||||
|
@ -31,7 +31,7 @@ const (
|
|||||||
InvalidProxyCallback string = "INVALID_PROXY_CALLBACK"
|
InvalidProxyCallback string = "INVALID_PROXY_CALLBACK"
|
||||||
InvalidTicket string = "INVALID_TICKET"
|
InvalidTicket string = "INVALID_TICKET"
|
||||||
InvalidService string = "INVALID_SERVICE"
|
InvalidService string = "INVALID_SERVICE"
|
||||||
InteralError string = "INTERNAL_ERROR"
|
InternalError string = "INTERNAL_ERROR"
|
||||||
UnauthorizedService string = "UNAUTHORIZED_SERVICE"
|
UnauthorizedService string = "UNAUTHORIZED_SERVICE"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ func (c *RootController) CasP3ServiceAndProxyValidate() {
|
|||||||
}
|
}
|
||||||
// make a request to pgturl passing pgt and pgtiou
|
// make a request to pgturl passing pgt and pgtiou
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.sendCasAuthenticationResponseErr(InteralError, err.Error(), format)
|
c.sendCasAuthenticationResponseErr(InternalError, err.Error(), format)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
param := pgtUrlObj.Query()
|
param := pgtUrlObj.Query()
|
||||||
@ -126,7 +126,7 @@ func (c *RootController) CasP3ServiceAndProxyValidate() {
|
|||||||
|
|
||||||
request, err := http.NewRequest("GET", pgtUrlObj.String(), nil)
|
request, err := http.NewRequest("GET", pgtUrlObj.String(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.sendCasAuthenticationResponseErr(InteralError, err.Error(), format)
|
c.sendCasAuthenticationResponseErr(InternalError, err.Error(), format)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,7 +214,7 @@ func (c *RootController) SamlValidate() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
envelopReponse := struct {
|
envelopResponse := struct {
|
||||||
XMLName xml.Name `xml:"SOAP-ENV:Envelope"`
|
XMLName xml.Name `xml:"SOAP-ENV:Envelope"`
|
||||||
Xmlns string `xml:"xmlns:SOAP-ENV"`
|
Xmlns string `xml:"xmlns:SOAP-ENV"`
|
||||||
Body struct {
|
Body struct {
|
||||||
@ -222,15 +222,15 @@ func (c *RootController) SamlValidate() {
|
|||||||
Content string `xml:",innerxml"`
|
Content string `xml:",innerxml"`
|
||||||
}
|
}
|
||||||
}{}
|
}{}
|
||||||
envelopReponse.Xmlns = "http://schemas.xmlsoap.org/soap/envelope/"
|
envelopResponse.Xmlns = "http://schemas.xmlsoap.org/soap/envelope/"
|
||||||
envelopReponse.Body.Content = response
|
envelopResponse.Body.Content = response
|
||||||
|
|
||||||
data, err := xml.Marshal(envelopReponse)
|
data, err := xml.Marshal(envelopResponse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ResponseError(err.Error())
|
c.ResponseError(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.Ctx.Output.Body([]byte(data))
|
c.Ctx.Output.Body(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *RootController) sendCasProxyResponseErr(code, msg, format string) {
|
func (c *RootController) sendCasProxyResponseErr(code, msg, format string) {
|
||||||
|
@ -48,6 +48,7 @@ func (c *ApiController) GetCerts() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetCert
|
||||||
// @Title GetCert
|
// @Title GetCert
|
||||||
// @Tag Cert API
|
// @Tag Cert API
|
||||||
// @Description get cert
|
// @Description get cert
|
||||||
@ -61,6 +62,7 @@ func (c *ApiController) GetCert() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateCert
|
||||||
// @Title UpdateCert
|
// @Title UpdateCert
|
||||||
// @Tag Cert API
|
// @Tag Cert API
|
||||||
// @Description update cert
|
// @Description update cert
|
||||||
@ -81,6 +83,7 @@ func (c *ApiController) UpdateCert() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddCert
|
||||||
// @Title AddCert
|
// @Title AddCert
|
||||||
// @Tag Cert API
|
// @Tag Cert API
|
||||||
// @Description add cert
|
// @Description add cert
|
||||||
@ -98,6 +101,7 @@ func (c *ApiController) AddCert() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteCert
|
||||||
// @Title DeleteCert
|
// @Title DeleteCert
|
||||||
// @Tag Cert API
|
// @Tag Cert API
|
||||||
// @Description delete cert
|
// @Description delete cert
|
||||||
|
@ -44,6 +44,7 @@ type LdapSyncResp struct {
|
|||||||
Failed []object.LdapRespUser `json:"failed"`
|
Failed []object.LdapRespUser `json:"failed"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetLdapUser
|
||||||
// @Tag Account API
|
// @Tag Account API
|
||||||
// @Title GetLdapser
|
// @Title GetLdapser
|
||||||
// @router /get-ldap-user [post]
|
// @router /get-ldap-user [post]
|
||||||
@ -100,6 +101,7 @@ func (c *ApiController) GetLdapUser() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetLdaps
|
||||||
// @Tag Account API
|
// @Tag Account API
|
||||||
// @Title GetLdaps
|
// @Title GetLdaps
|
||||||
// @router /get-ldaps [post]
|
// @router /get-ldaps [post]
|
||||||
@ -110,6 +112,7 @@ func (c *ApiController) GetLdaps() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetLdap
|
||||||
// @Tag Account API
|
// @Tag Account API
|
||||||
// @Title GetLdap
|
// @Title GetLdap
|
||||||
// @router /get-ldap [post]
|
// @router /get-ldap [post]
|
||||||
@ -125,6 +128,7 @@ func (c *ApiController) GetLdap() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddLdap
|
||||||
// @Tag Account API
|
// @Tag Account API
|
||||||
// @Title AddLdap
|
// @Title AddLdap
|
||||||
// @router /add-ldap [post]
|
// @router /add-ldap [post]
|
||||||
@ -159,6 +163,7 @@ func (c *ApiController) AddLdap() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateLdap
|
||||||
// @Tag Account API
|
// @Tag Account API
|
||||||
// @Title UpdateLdap
|
// @Title UpdateLdap
|
||||||
// @router /update-ldap [post]
|
// @router /update-ldap [post]
|
||||||
@ -186,6 +191,7 @@ func (c *ApiController) UpdateLdap() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteLdap
|
||||||
// @Tag Account API
|
// @Tag Account API
|
||||||
// @Title DeleteLdap
|
// @Title DeleteLdap
|
||||||
// @router /delete-ldap [post]
|
// @router /delete-ldap [post]
|
||||||
@ -201,6 +207,7 @@ func (c *ApiController) DeleteLdap() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SyncLdapUsers
|
||||||
// @Tag Account API
|
// @Tag Account API
|
||||||
// @Title SyncLdapUsers
|
// @Title SyncLdapUsers
|
||||||
// @router /sync-ldap-users [post]
|
// @router /sync-ldap-users [post]
|
||||||
@ -223,6 +230,7 @@ func (c *ApiController) SyncLdapUsers() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CheckLdapUsersExist
|
||||||
// @Tag Account API
|
// @Tag Account API
|
||||||
// @Title CheckLdapUserExist
|
// @Title CheckLdapUserExist
|
||||||
// @router /check-ldap-users-exist [post]
|
// @router /check-ldap-users-exist [post]
|
||||||
|
@ -16,6 +16,7 @@ package controllers
|
|||||||
|
|
||||||
import "github.com/casdoor/casdoor/object"
|
import "github.com/casdoor/casdoor/object"
|
||||||
|
|
||||||
|
// GetOidcDiscovery
|
||||||
// @Title GetOidcDiscovery
|
// @Title GetOidcDiscovery
|
||||||
// @Tag OIDC API
|
// @Tag OIDC API
|
||||||
// @Description Get Oidc Discovery
|
// @Description Get Oidc Discovery
|
||||||
@ -27,6 +28,7 @@ func (c *RootController) GetOidcDiscovery() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetJwks
|
||||||
// @Title GetJwks
|
// @Title GetJwks
|
||||||
// @Tag OIDC API
|
// @Tag OIDC API
|
||||||
// @Success 200 {object} jose.JSONWebKey
|
// @Success 200 {object} jose.JSONWebKey
|
||||||
|
@ -67,6 +67,7 @@ func (c *ApiController) GetUserPayments() {
|
|||||||
c.ResponseOk(payments)
|
c.ResponseOk(payments)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetPayment
|
||||||
// @Title GetPayment
|
// @Title GetPayment
|
||||||
// @Tag Payment API
|
// @Tag Payment API
|
||||||
// @Description get payment
|
// @Description get payment
|
||||||
@ -80,6 +81,7 @@ func (c *ApiController) GetPayment() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdatePayment
|
||||||
// @Title UpdatePayment
|
// @Title UpdatePayment
|
||||||
// @Tag Payment API
|
// @Tag Payment API
|
||||||
// @Description update payment
|
// @Description update payment
|
||||||
@ -100,6 +102,7 @@ func (c *ApiController) UpdatePayment() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddPayment
|
||||||
// @Title AddPayment
|
// @Title AddPayment
|
||||||
// @Tag Payment API
|
// @Tag Payment API
|
||||||
// @Description add payment
|
// @Description add payment
|
||||||
@ -117,6 +120,7 @@ func (c *ApiController) AddPayment() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeletePayment
|
||||||
// @Title DeletePayment
|
// @Title DeletePayment
|
||||||
// @Tag Payment API
|
// @Tag Payment API
|
||||||
// @Description delete payment
|
// @Description delete payment
|
||||||
@ -134,6 +138,7 @@ func (c *ApiController) DeletePayment() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NotifyPayment
|
||||||
// @Title NotifyPayment
|
// @Title NotifyPayment
|
||||||
// @Tag Payment API
|
// @Tag Payment API
|
||||||
// @Description notify payment
|
// @Description notify payment
|
||||||
@ -159,6 +164,7 @@ func (c *ApiController) NotifyPayment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InvoicePayment
|
||||||
// @Title InvoicePayment
|
// @Title InvoicePayment
|
||||||
// @Tag Payment API
|
// @Tag Payment API
|
||||||
// @Description invoice payment
|
// @Description invoice payment
|
||||||
|
@ -48,6 +48,7 @@ func (c *ApiController) GetPermissions() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetPermission
|
||||||
// @Title GetPermission
|
// @Title GetPermission
|
||||||
// @Tag Permission API
|
// @Tag Permission API
|
||||||
// @Description get permission
|
// @Description get permission
|
||||||
@ -61,6 +62,7 @@ func (c *ApiController) GetPermission() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdatePermission
|
||||||
// @Title UpdatePermission
|
// @Title UpdatePermission
|
||||||
// @Tag Permission API
|
// @Tag Permission API
|
||||||
// @Description update permission
|
// @Description update permission
|
||||||
@ -81,6 +83,7 @@ func (c *ApiController) UpdatePermission() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddPermission
|
||||||
// @Title AddPermission
|
// @Title AddPermission
|
||||||
// @Tag Permission API
|
// @Tag Permission API
|
||||||
// @Description add permission
|
// @Description add permission
|
||||||
@ -98,6 +101,7 @@ func (c *ApiController) AddPermission() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeletePermission
|
||||||
// @Title DeletePermission
|
// @Title DeletePermission
|
||||||
// @Tag Permission API
|
// @Tag Permission API
|
||||||
// @Description delete permission
|
// @Description delete permission
|
||||||
|
@ -49,6 +49,7 @@ func (c *ApiController) GetProducts() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetProduct
|
||||||
// @Title GetProduct
|
// @Title GetProduct
|
||||||
// @Tag Product API
|
// @Tag Product API
|
||||||
// @Description get product
|
// @Description get product
|
||||||
@ -65,6 +66,7 @@ func (c *ApiController) GetProduct() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateProduct
|
||||||
// @Title UpdateProduct
|
// @Title UpdateProduct
|
||||||
// @Tag Product API
|
// @Tag Product API
|
||||||
// @Description update product
|
// @Description update product
|
||||||
@ -85,6 +87,7 @@ func (c *ApiController) UpdateProduct() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddProduct
|
||||||
// @Title AddProduct
|
// @Title AddProduct
|
||||||
// @Tag Product API
|
// @Tag Product API
|
||||||
// @Description add product
|
// @Description add product
|
||||||
@ -102,6 +105,7 @@ func (c *ApiController) AddProduct() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteProduct
|
||||||
// @Title DeleteProduct
|
// @Title DeleteProduct
|
||||||
// @Tag Product API
|
// @Tag Product API
|
||||||
// @Description delete product
|
// @Description delete product
|
||||||
@ -119,6 +123,7 @@ func (c *ApiController) DeleteProduct() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BuyProduct
|
||||||
// @Title BuyProduct
|
// @Title BuyProduct
|
||||||
// @Tag Product API
|
// @Tag Product API
|
||||||
// @Description buy product
|
// @Description buy product
|
||||||
|
@ -48,6 +48,7 @@ func (c *ApiController) GetProviders() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetProvider
|
||||||
// @Title GetProvider
|
// @Title GetProvider
|
||||||
// @Tag Provider API
|
// @Tag Provider API
|
||||||
// @Description get provider
|
// @Description get provider
|
||||||
@ -61,6 +62,7 @@ func (c *ApiController) GetProvider() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateProvider
|
||||||
// @Title UpdateProvider
|
// @Title UpdateProvider
|
||||||
// @Tag Provider API
|
// @Tag Provider API
|
||||||
// @Description update provider
|
// @Description update provider
|
||||||
@ -81,6 +83,7 @@ func (c *ApiController) UpdateProvider() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddProvider
|
||||||
// @Title AddProvider
|
// @Title AddProvider
|
||||||
// @Tag Provider API
|
// @Tag Provider API
|
||||||
// @Description add provider
|
// @Description add provider
|
||||||
@ -98,6 +101,7 @@ func (c *ApiController) AddProvider() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteProvider
|
||||||
// @Title DeleteProvider
|
// @Title DeleteProvider
|
||||||
// @Tag Provider API
|
// @Tag Provider API
|
||||||
// @Description delete provider
|
// @Description delete provider
|
||||||
|
@ -27,6 +27,7 @@ import (
|
|||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GetResources
|
||||||
// @router /get-resources [get]
|
// @router /get-resources [get]
|
||||||
// @Tag Resource API
|
// @Tag Resource API
|
||||||
// @Title GetResources
|
// @Title GetResources
|
||||||
@ -50,6 +51,7 @@ func (c *ApiController) GetResources() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetResource
|
||||||
// @Tag Resource API
|
// @Tag Resource API
|
||||||
// @Title GetResource
|
// @Title GetResource
|
||||||
// @router /get-resource [get]
|
// @router /get-resource [get]
|
||||||
@ -60,6 +62,7 @@ func (c *ApiController) GetResource() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateResource
|
||||||
// @Tag Resource API
|
// @Tag Resource API
|
||||||
// @Title UpdateResource
|
// @Title UpdateResource
|
||||||
// @router /update-resource [post]
|
// @router /update-resource [post]
|
||||||
@ -76,6 +79,7 @@ func (c *ApiController) UpdateResource() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddResource
|
||||||
// @Tag Resource API
|
// @Tag Resource API
|
||||||
// @Title AddResource
|
// @Title AddResource
|
||||||
// @router /add-resource [post]
|
// @router /add-resource [post]
|
||||||
@ -90,6 +94,7 @@ func (c *ApiController) AddResource() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteResource
|
||||||
// @Tag Resource API
|
// @Tag Resource API
|
||||||
// @Title DeleteResource
|
// @Title DeleteResource
|
||||||
// @router /delete-resource [post]
|
// @router /delete-resource [post]
|
||||||
@ -115,6 +120,7 @@ func (c *ApiController) DeleteResource() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UploadResource
|
||||||
// @Tag Resource API
|
// @Tag Resource API
|
||||||
// @Title UploadResource
|
// @Title UploadResource
|
||||||
// @router /upload-resource [post]
|
// @router /upload-resource [post]
|
||||||
|
@ -48,6 +48,7 @@ func (c *ApiController) GetRoles() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetRole
|
||||||
// @Title GetRole
|
// @Title GetRole
|
||||||
// @Tag Role API
|
// @Tag Role API
|
||||||
// @Description get role
|
// @Description get role
|
||||||
@ -61,6 +62,7 @@ func (c *ApiController) GetRole() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateRole
|
||||||
// @Title UpdateRole
|
// @Title UpdateRole
|
||||||
// @Tag Role API
|
// @Tag Role API
|
||||||
// @Description update role
|
// @Description update role
|
||||||
@ -81,6 +83,7 @@ func (c *ApiController) UpdateRole() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddRole
|
||||||
// @Title AddRole
|
// @Title AddRole
|
||||||
// @Tag Role API
|
// @Tag Role API
|
||||||
// @Description add role
|
// @Description add role
|
||||||
@ -98,6 +101,7 @@ func (c *ApiController) AddRole() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteRole
|
||||||
// @Title DeleteRole
|
// @Title DeleteRole
|
||||||
// @Tag Role API
|
// @Tag Role API
|
||||||
// @Description delete role
|
// @Description delete role
|
||||||
|
@ -48,6 +48,7 @@ func (c *ApiController) GetSyncers() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetSyncer
|
||||||
// @Title GetSyncer
|
// @Title GetSyncer
|
||||||
// @Tag Syncer API
|
// @Tag Syncer API
|
||||||
// @Description get syncer
|
// @Description get syncer
|
||||||
@ -61,6 +62,7 @@ func (c *ApiController) GetSyncer() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateSyncer
|
||||||
// @Title UpdateSyncer
|
// @Title UpdateSyncer
|
||||||
// @Tag Syncer API
|
// @Tag Syncer API
|
||||||
// @Description update syncer
|
// @Description update syncer
|
||||||
@ -81,6 +83,7 @@ func (c *ApiController) UpdateSyncer() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddSyncer
|
||||||
// @Title AddSyncer
|
// @Title AddSyncer
|
||||||
// @Tag Syncer API
|
// @Tag Syncer API
|
||||||
// @Description add syncer
|
// @Description add syncer
|
||||||
@ -98,6 +101,7 @@ func (c *ApiController) AddSyncer() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteSyncer
|
||||||
// @Title DeleteSyncer
|
// @Title DeleteSyncer
|
||||||
// @Tag Syncer API
|
// @Tag Syncer API
|
||||||
// @Description delete syncer
|
// @Description delete syncer
|
||||||
@ -115,6 +119,7 @@ func (c *ApiController) DeleteSyncer() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RunSyncer
|
||||||
// @Title RunSyncer
|
// @Title RunSyncer
|
||||||
// @Tag Syncer API
|
// @Tag Syncer API
|
||||||
// @Description run syncer
|
// @Description run syncer
|
||||||
|
@ -255,7 +255,7 @@ func (c *ApiController) RefreshToken() {
|
|||||||
// @router /login/oauth/logout [get]
|
// @router /login/oauth/logout [get]
|
||||||
func (c *ApiController) TokenLogout() {
|
func (c *ApiController) TokenLogout() {
|
||||||
token := c.Input().Get("id_token_hint")
|
token := c.Input().Get("id_token_hint")
|
||||||
flag, application := object.DeleteTokenByAceessToken(token)
|
flag, application := object.DeleteTokenByAccessToken(token)
|
||||||
redirectUri := c.Input().Get("post_logout_redirect_uri")
|
redirectUri := c.Input().Get("post_logout_redirect_uri")
|
||||||
state := c.Input().Get("state")
|
state := c.Input().Get("state")
|
||||||
if application != nil && object.CheckRedirectUriValid(application, redirectUri) {
|
if application != nil && object.CheckRedirectUriValid(application, redirectUri) {
|
||||||
@ -288,7 +288,7 @@ func (c *ApiController) IntrospectToken() {
|
|||||||
if clientId == "" || clientSecret == "" {
|
if clientId == "" || clientSecret == "" {
|
||||||
c.ResponseError("empty clientId or clientSecret")
|
c.ResponseError("empty clientId or clientSecret")
|
||||||
c.Data["json"] = &object.TokenError{
|
c.Data["json"] = &object.TokenError{
|
||||||
Error: object.INVALID_REQUEST,
|
Error: object.InvalidRequest,
|
||||||
}
|
}
|
||||||
c.SetTokenErrorHttpStatus()
|
c.SetTokenErrorHttpStatus()
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
@ -299,7 +299,7 @@ func (c *ApiController) IntrospectToken() {
|
|||||||
if application == nil || application.ClientSecret != clientSecret {
|
if application == nil || application.ClientSecret != clientSecret {
|
||||||
c.ResponseError("invalid application or wrong clientSecret")
|
c.ResponseError("invalid application or wrong clientSecret")
|
||||||
c.Data["json"] = &object.TokenError{
|
c.Data["json"] = &object.TokenError{
|
||||||
Error: object.INVALID_CLIENT,
|
Error: object.InvalidClient,
|
||||||
}
|
}
|
||||||
c.SetTokenErrorHttpStatus()
|
c.SetTokenErrorHttpStatus()
|
||||||
return
|
return
|
||||||
|
@ -298,6 +298,7 @@ func (c *ApiController) SetPassword() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CheckUserPassword
|
||||||
// @Title CheckUserPassword
|
// @Title CheckUserPassword
|
||||||
// @router /check-user-password [post]
|
// @router /check-user-password [post]
|
||||||
// @Tag User API
|
// @Tag User API
|
||||||
|
@ -55,7 +55,7 @@ func (c *ApiController) ResponseError(error string, data ...interface{}) {
|
|||||||
func (c *ApiController) SetTokenErrorHttpStatus() {
|
func (c *ApiController) SetTokenErrorHttpStatus() {
|
||||||
_, ok := c.Data["json"].(*object.TokenError)
|
_, ok := c.Data["json"].(*object.TokenError)
|
||||||
if ok {
|
if ok {
|
||||||
if c.Data["json"].(*object.TokenError).Error == object.INVALID_CLIENT {
|
if c.Data["json"].(*object.TokenError).Error == object.InvalidClient {
|
||||||
c.Ctx.Output.SetStatus(401)
|
c.Ctx.Output.SetStatus(401)
|
||||||
c.Ctx.Output.Header("WWW-Authenticate", "Basic realm=\"OAuth2\"")
|
c.Ctx.Output.Header("WWW-Authenticate", "Basic realm=\"OAuth2\"")
|
||||||
} else {
|
} else {
|
||||||
|
@ -98,7 +98,7 @@ func (c *ApiController) SendVerificationCode() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
sendResp := errors.New("Invalid dest type")
|
sendResp := errors.New("invalid dest type")
|
||||||
|
|
||||||
if user == nil && checkUser != "" && checkUser != "true" {
|
if user == nil && checkUser != "" && checkUser != "true" {
|
||||||
name := application.Organization
|
name := application.Organization
|
||||||
|
@ -16,7 +16,7 @@ package controllers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io"
|
||||||
|
|
||||||
"github.com/casdoor/casdoor/object"
|
"github.com/casdoor/casdoor/object"
|
||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/duo-labs/webauthn/webauthn"
|
"github.com/duo-labs/webauthn/webauthn"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// WebAuthnSignupBegin
|
||||||
// @Title WebAuthnSignupBegin
|
// @Title WebAuthnSignupBegin
|
||||||
// @Tag User API
|
// @Tag User API
|
||||||
// @Description WebAuthn Registration Flow 1st stage
|
// @Description WebAuthn Registration Flow 1st stage
|
||||||
@ -53,6 +54,7 @@ func (c *ApiController) WebAuthnSignupBegin() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WebAuthnSignupFinish
|
||||||
// @Title WebAuthnSignupFinish
|
// @Title WebAuthnSignupFinish
|
||||||
// @Tag User API
|
// @Tag User API
|
||||||
// @Description WebAuthn Registration Flow 2nd stage
|
// @Description WebAuthn Registration Flow 2nd stage
|
||||||
@ -72,7 +74,7 @@ func (c *ApiController) WebAuthnSignupFinish() {
|
|||||||
c.ResponseError("Please call WebAuthnSignupBegin first")
|
c.ResponseError("Please call WebAuthnSignupBegin first")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.Ctx.Request.Body = ioutil.NopCloser(bytes.NewBuffer(c.Ctx.Input.RequestBody))
|
c.Ctx.Request.Body = io.NopCloser(bytes.NewBuffer(c.Ctx.Input.RequestBody))
|
||||||
|
|
||||||
credential, err := webauthnObj.FinishRegistration(user, sessionData, c.Ctx.Request)
|
credential, err := webauthnObj.FinishRegistration(user, sessionData, c.Ctx.Request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -84,6 +86,7 @@ func (c *ApiController) WebAuthnSignupFinish() {
|
|||||||
c.ResponseOk()
|
c.ResponseOk()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WebAuthnSigninBegin
|
||||||
// @Title WebAuthnSigninBegin
|
// @Title WebAuthnSigninBegin
|
||||||
// @Tag Login API
|
// @Tag Login API
|
||||||
// @Description WebAuthn Login Flow 1st stage
|
// @Description WebAuthn Login Flow 1st stage
|
||||||
@ -110,6 +113,7 @@ func (c *ApiController) WebAuthnSigninBegin() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WebAuthnSigninFinish
|
||||||
// @Title WebAuthnSigninBegin
|
// @Title WebAuthnSigninBegin
|
||||||
// @Tag Login API
|
// @Tag Login API
|
||||||
// @Description WebAuthn Login Flow 2nd stage
|
// @Description WebAuthn Login Flow 2nd stage
|
||||||
@ -124,7 +128,7 @@ func (c *ApiController) WebAuthnSigninFinish() {
|
|||||||
c.ResponseError("Please call WebAuthnSigninBegin first")
|
c.ResponseError("Please call WebAuthnSigninBegin first")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.Ctx.Request.Body = ioutil.NopCloser(bytes.NewBuffer(c.Ctx.Input.RequestBody))
|
c.Ctx.Request.Body = io.NopCloser(bytes.NewBuffer(c.Ctx.Input.RequestBody))
|
||||||
userId := string(sessionData.UserID)
|
userId := string(sessionData.UserID)
|
||||||
user := object.GetUser(userId)
|
user := object.GetUser(userId)
|
||||||
_, err := webauthnObj.FinishLogin(user, sessionData, c.Ctx.Request)
|
_, err := webauthnObj.FinishLogin(user, sessionData, c.Ctx.Request)
|
||||||
|
@ -48,6 +48,7 @@ func (c *ApiController) GetWebhooks() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetWebhook
|
||||||
// @Title GetWebhook
|
// @Title GetWebhook
|
||||||
// @Tag Webhook API
|
// @Tag Webhook API
|
||||||
// @Description get webhook
|
// @Description get webhook
|
||||||
@ -61,6 +62,7 @@ func (c *ApiController) GetWebhook() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateWebhook
|
||||||
// @Title UpdateWebhook
|
// @Title UpdateWebhook
|
||||||
// @Tag Webhook API
|
// @Tag Webhook API
|
||||||
// @Description update webhook
|
// @Description update webhook
|
||||||
@ -81,6 +83,7 @@ func (c *ApiController) UpdateWebhook() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddWebhook
|
||||||
// @Title AddWebhook
|
// @Title AddWebhook
|
||||||
// @Tag Webhook API
|
// @Tag Webhook API
|
||||||
// @Description add webhook
|
// @Description add webhook
|
||||||
@ -98,6 +101,7 @@ func (c *ApiController) AddWebhook() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteWebhook
|
||||||
// @Title DeleteWebhook
|
// @Title DeleteWebhook
|
||||||
// @Tag Webhook API
|
// @Tag Webhook API
|
||||||
// @Description delete webhook
|
// @Description delete webhook
|
||||||
|
14
idp/adfs.go
14
idp/adfs.go
@ -19,7 +19,7 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
@ -77,6 +77,7 @@ type AdfsToken struct {
|
|||||||
ErrMsg string `json:"error_description"`
|
ErrMsg string `json:"error_description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetToken
|
||||||
// get more detail via: https://docs.microsoft.com/en-us/windows-server/identity/ad-fs/overview/ad-fs-openid-connect-oauth-flows-scenarios#request-an-access-token
|
// get more detail via: https://docs.microsoft.com/en-us/windows-server/identity/ad-fs/overview/ad-fs-openid-connect-oauth-flows-scenarios#request-an-access-token
|
||||||
func (idp *AdfsIdProvider) GetToken(code string) (*oauth2.Token, error) {
|
func (idp *AdfsIdProvider) GetToken(code string) (*oauth2.Token, error) {
|
||||||
payload := url.Values{}
|
payload := url.Values{}
|
||||||
@ -88,7 +89,7 @@ func (idp *AdfsIdProvider) GetToken(code string) (*oauth2.Token, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -109,6 +110,7 @@ func (idp *AdfsIdProvider) GetToken(code string) (*oauth2.Token, error) {
|
|||||||
return token, nil
|
return token, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUserInfo
|
||||||
// Since the userinfo endpoint of ADFS only returns sub,
|
// Since the userinfo endpoint of ADFS only returns sub,
|
||||||
// the id_token is used to resolve the userinfo
|
// the id_token is used to resolve the userinfo
|
||||||
func (idp *AdfsIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error) {
|
func (idp *AdfsIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error) {
|
||||||
@ -122,10 +124,10 @@ func (idp *AdfsIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error) {
|
|||||||
}
|
}
|
||||||
tokenSrc := []byte(token.AccessToken)
|
tokenSrc := []byte(token.AccessToken)
|
||||||
publicKey, _ := keyset.Keys[0].Materialize()
|
publicKey, _ := keyset.Keys[0].Materialize()
|
||||||
id_token, _ := jwt.Parse(bytes.NewReader(tokenSrc), jwt.WithVerify(jwa.RS256, publicKey))
|
idToken, _ := jwt.Parse(bytes.NewReader(tokenSrc), jwt.WithVerify(jwa.RS256, publicKey))
|
||||||
sid, _ := id_token.Get("sid")
|
sid, _ := idToken.Get("sid")
|
||||||
upn, _ := id_token.Get("upn")
|
upn, _ := idToken.Get("upn")
|
||||||
name, _ := id_token.Get("unique_name")
|
name, _ := idToken.Get("unique_name")
|
||||||
userinfo := &UserInfo{
|
userinfo := &UserInfo{
|
||||||
Id: sid.(string),
|
Id: sid.(string),
|
||||||
Username: name.(string),
|
Username: name.(string),
|
||||||
|
@ -24,7 +24,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"sort"
|
"sort"
|
||||||
@ -205,7 +204,7 @@ func (idp *AlipayIdProvider) postWithBody(body interface{}, targetUrl string) ([
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
@ -97,7 +97,7 @@ func (idp *BaiduIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
@ -76,6 +75,7 @@ type BilibiliIdProviderTokenResponse struct {
|
|||||||
Data BilibiliProviderToken `json:"data"`
|
Data BilibiliProviderToken `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetToken
|
||||||
/*
|
/*
|
||||||
{
|
{
|
||||||
"code": 0,
|
"code": 0,
|
||||||
@ -170,7 +170,7 @@ func (idp *BilibiliIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, erro
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -204,7 +204,7 @@ func (idp *BilibiliIdProvider) postWithBody(body interface{}, url string) ([]byt
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ package idp
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
@ -71,7 +71,7 @@ func (idp *CasdoorIdProvider) GetToken(code string) (*oauth2.Token, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -131,7 +131,7 @@ func (idp *CasdoorIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
_ "net/url"
|
_ "net/url"
|
||||||
_ "time"
|
_ "time"
|
||||||
@ -84,7 +84,7 @@ func (idp *CustomIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error)
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -101,7 +100,7 @@ func (idp *DingTalkIdProvider) GetToken(code string) (*oauth2.Token, error) {
|
|||||||
|
|
||||||
token := &oauth2.Token{
|
token := &oauth2.Token{
|
||||||
AccessToken: pToken.AccessToken,
|
AccessToken: pToken.AccessToken,
|
||||||
Expiry: time.Unix(time.Now().Unix()+int64(pToken.ExpiresIn), 0),
|
Expiry: time.Unix(time.Now().Unix()+pToken.ExpiresIn, 0),
|
||||||
}
|
}
|
||||||
return token, nil
|
return token, nil
|
||||||
}
|
}
|
||||||
@ -145,7 +144,7 @@ func (idp *DingTalkIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, erro
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -180,7 +179,7 @@ func (idp *DingTalkIdProvider) postWithBody(body interface{}, url string) ([]byt
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
@ -98,7 +98,7 @@ func (idp *DouyinIdProvider) GetToken(code string) (*oauth2.Token, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -177,7 +177,7 @@ func (idp *DouyinIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error)
|
|||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
respBody, err := ioutil.ReadAll(resp.Body)
|
respBody, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,7 @@ type FacebookCheckToken struct {
|
|||||||
Data string `json:"data"`
|
Data string `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FacebookCheckTokenData
|
||||||
// Get more detail via: https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow#checktoken
|
// Get more detail via: https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow#checktoken
|
||||||
type FacebookCheckTokenData struct {
|
type FacebookCheckTokenData struct {
|
||||||
UserId string `json:"user_id"`
|
UserId string `json:"user_id"`
|
||||||
|
@ -19,7 +19,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -93,7 +92,7 @@ func (idp *GiteeIdProvider) GetToken(code string) (*oauth2.Token, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
rbs, err := ioutil.ReadAll(resp.Body)
|
rbs, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -202,7 +201,7 @@ func (idp *GithubIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error)
|
|||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -236,7 +235,7 @@ func (idp *GithubIdProvider) postWithBody(body interface{}, url string) ([]byte,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ package idp
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -85,7 +85,7 @@ func (idp *GitlabIdProvider) GetToken(code string) (*oauth2.Token, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -209,7 +209,7 @@ func (idp *GitlabIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
@ -95,7 +95,7 @@ func (idp *GoogleIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -207,6 +207,7 @@ func NewGothIdProvider(providerType string, clientId string, clientSecret string
|
|||||||
return &idp
|
return &idp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetHttpClient
|
||||||
// Goth's idp all implement the Client method, but since the goth.Provider interface does not provide to modify idp's client method, reflection is required
|
// Goth's idp all implement the Client method, but since the goth.Provider interface does not provide to modify idp's client method, reflection is required
|
||||||
func (idp *GothIdProvider) SetHttpClient(client *http.Client) {
|
func (idp *GothIdProvider) SetHttpClient(client *http.Client) {
|
||||||
idpClient := reflect.ValueOf(idp.Provider).Elem().FieldByName("HTTPClient")
|
idpClient := reflect.ValueOf(idp.Provider).Elem().FieldByName("HTTPClient")
|
||||||
|
@ -17,7 +17,7 @@ package idp
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
@ -58,6 +58,7 @@ type InfoflowInterToken struct {
|
|||||||
AccessToken string `json:"access_token"`
|
AccessToken string `json:"access_token"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetToken
|
||||||
// get more detail via: https://qy.baidu.com/doc/index.html#/inner_quickstart/flow?id=%E8%8E%B7%E5%8F%96accesstoken
|
// get more detail via: https://qy.baidu.com/doc/index.html#/inner_quickstart/flow?id=%E8%8E%B7%E5%8F%96accesstoken
|
||||||
func (idp *InfoflowInternalIdProvider) GetToken(code string) (*oauth2.Token, error) {
|
func (idp *InfoflowInternalIdProvider) GetToken(code string) (*oauth2.Token, error) {
|
||||||
pTokenParams := &struct {
|
pTokenParams := &struct {
|
||||||
@ -69,7 +70,7 @@ func (idp *InfoflowInternalIdProvider) GetToken(code string) (*oauth2.Token, err
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -137,6 +138,7 @@ type InfoflowInternalUserInfo struct {
|
|||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUserInfo
|
||||||
// get more detail via: https://qy.baidu.com/doc/index.html#/inner_serverapi/contacts?id=%e8%8e%b7%e5%8f%96%e6%88%90%e5%91%98
|
// get more detail via: https://qy.baidu.com/doc/index.html#/inner_serverapi/contacts?id=%e8%8e%b7%e5%8f%96%e6%88%90%e5%91%98
|
||||||
func (idp *InfoflowInternalIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error) {
|
func (idp *InfoflowInternalIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error) {
|
||||||
// Get userid first
|
// Get userid first
|
||||||
@ -147,7 +149,7 @@ func (idp *InfoflowInternalIdProvider) GetUserInfo(token *oauth2.Token) (*UserIn
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -165,7 +167,7 @@ func (idp *InfoflowInternalIdProvider) GetUserInfo(token *oauth2.Token) (*UserIn
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err = ioutil.ReadAll(resp.Body)
|
data, err = io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -63,6 +62,7 @@ type InfoflowToken struct {
|
|||||||
ExpiresIn int `json:"expires_in"`
|
ExpiresIn int `json:"expires_in"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetToken
|
||||||
// get more detail via: https://qy.baidu.com/doc/index.html#/third_serverapi/authority
|
// get more detail via: https://qy.baidu.com/doc/index.html#/third_serverapi/authority
|
||||||
func (idp *InfoflowIdProvider) GetToken(code string) (*oauth2.Token, error) {
|
func (idp *InfoflowIdProvider) GetToken(code string) (*oauth2.Token, error) {
|
||||||
pTokenParams := &struct {
|
pTokenParams := &struct {
|
||||||
@ -134,6 +134,7 @@ type InfoflowUserInfo struct {
|
|||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUserInfo
|
||||||
// get more detail via: https://qy.baidu.com/doc/index.html#/third_serverapi/contacts?id=%e8%8e%b7%e5%8f%96%e6%88%90%e5%91%98
|
// get more detail via: https://qy.baidu.com/doc/index.html#/third_serverapi/contacts?id=%e8%8e%b7%e5%8f%96%e6%88%90%e5%91%98
|
||||||
func (idp *InfoflowIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error) {
|
func (idp *InfoflowIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error) {
|
||||||
// Get userid first
|
// Get userid first
|
||||||
@ -144,7 +145,7 @@ func (idp *InfoflowIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, erro
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -162,7 +163,7 @@ func (idp *InfoflowIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, erro
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err = ioutil.ReadAll(resp.Body)
|
data, err = io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -197,7 +198,7 @@ func (idp *InfoflowIdProvider) postWithBody(body interface{}, url string) ([]byt
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ package idp
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -173,7 +172,7 @@ func (idp *LarkIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
data, err = ioutil.ReadAll(resp.Body)
|
data, err = io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -204,7 +203,7 @@ func (idp *LarkIdProvider) postWithBody(body interface{}, url string) ([]byte, e
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
@ -85,7 +84,7 @@ func (idp *LinkedInIdProvider) GetToken(code string) (*oauth2.Token, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
rbs, err := ioutil.ReadAll(resp.Body)
|
rbs, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -323,7 +322,7 @@ func (idp *LinkedInIdProvider) GetUrlRespWithAuthorization(url, token string) ([
|
|||||||
}
|
}
|
||||||
}(resp.Body)
|
}(resp.Body)
|
||||||
|
|
||||||
bs, err := ioutil.ReadAll(resp.Body)
|
bs, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ package idp
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
@ -114,7 +114,7 @@ func (idp *OktaIdProvider) GetToken(code string) (*oauth2.Token, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -178,7 +178,7 @@ func (idp *OktaIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error) {
|
|||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -75,7 +75,7 @@ func (idp *QqIdProvider) GetToken(code string) (*oauth2.Token, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
tokenContent, err := ioutil.ReadAll(resp.Body)
|
tokenContent, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -148,7 +148,7 @@ func (idp *QqIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
openIdBody, err := ioutil.ReadAll(resp.Body)
|
openIdBody, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -167,7 +167,7 @@ func (idp *QqIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
userInfoBody, err := ioutil.ReadAll(resp.Body)
|
userInfoBody, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ type WechatUserInfo struct {
|
|||||||
City string `json:"city"` // City filled in by general user's personal data
|
City string `json:"city"` // City filled in by general user's personal data
|
||||||
Province string `json:"province"` // Province filled in by ordinary user's personal information
|
Province string `json:"province"` // Province filled in by ordinary user's personal information
|
||||||
Country string `json:"country"` // Country, such as China is CN
|
Country string `json:"country"` // Country, such as China is CN
|
||||||
Headimgurl string `json:"headimgurl"` // User avatar, the last value represents the size of the square avatar (there are optional values of 0, 46, 64, 96, 132, 0 represents a 640*640 square avatar), this item is empty when the user does not have a avatar
|
Headimgurl string `json:"headimgurl"` // User avatar, the last value represents the size of the square avatar (there are optional values of 0, 46, 64, 96, 132, 0 represents a 640*640 square avatar), this item is empty when the user does not have an avatar
|
||||||
Privilege []string `json:"privilege"` // User Privilege information, json array, such as Wechat Woka user (chinaunicom)
|
Privilege []string `json:"privilege"` // User Privilege information, json array, such as Wechat Woka user (chinaunicom)
|
||||||
Unionid string `json:"unionid"` // Unified user identification. For an application under a WeChat open platform account, the unionid of the same user is unique.
|
Unionid string `json:"unionid"` // Unified user identification. For an application under a WeChat open platform account, the unionid of the same user is unique.
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ package idp
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
@ -65,7 +65,7 @@ func (idp *WeChatMiniProgramIdProvider) GetSessionByCode(code string) (*WeChatMi
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer sessionResponse.Body.Close()
|
defer sessionResponse.Body.Close()
|
||||||
data, err := ioutil.ReadAll(sessionResponse.Body)
|
data, err := io.ReadAll(sessionResponse.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,14 @@ package idp
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// WeComInternalIdProvider
|
||||||
// This idp is using wecom internal application api as idp
|
// This idp is using wecom internal application api as idp
|
||||||
type WeComInternalIdProvider struct {
|
type WeComInternalIdProvider struct {
|
||||||
Client *http.Client
|
Client *http.Client
|
||||||
@ -72,7 +73,7 @@ func (idp *WeComInternalIdProvider) GetToken(code string) (*oauth2.Token, error)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -123,7 +124,7 @@ func (idp *WeComInternalIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -144,7 +145,7 @@ func (idp *WeComInternalIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err = ioutil.ReadAll(resp.Body)
|
data, err = io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -195,7 +194,7 @@ func (idp *WeComIdProvider) postWithBody(body interface{}, url string) ([]byte,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -92,7 +91,7 @@ func (idp *WeiBoIdProvider) GetToken(code string) (*oauth2.Token, error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}(resp.Body)
|
}(resp.Body)
|
||||||
bs, err := ioutil.ReadAll(resp.Body)
|
bs, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ package object
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"io/ioutil"
|
"os"
|
||||||
|
|
||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
"github.com/duo-labs/webauthn/webauthn"
|
"github.com/duo-labs/webauthn/webauthn"
|
||||||
@ -158,11 +158,11 @@ func initBuiltInApplication() {
|
|||||||
func readTokenFromFile() (string, string) {
|
func readTokenFromFile() (string, string) {
|
||||||
pemPath := "./object/token_jwt_key.pem"
|
pemPath := "./object/token_jwt_key.pem"
|
||||||
keyPath := "./object/token_jwt_key.key"
|
keyPath := "./object/token_jwt_key.key"
|
||||||
pem, err := ioutil.ReadFile(pemPath)
|
pem, err := os.ReadFile(pemPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", ""
|
return "", ""
|
||||||
}
|
}
|
||||||
key, err := ioutil.ReadFile(keyPath)
|
key, err := os.ReadFile(keyPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", ""
|
return "", ""
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ func GetLdapAutoSynchronizer() *LdapAutoSynchronizer {
|
|||||||
return globalLdapAutoSynchronizer
|
return globalLdapAutoSynchronizer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StartAutoSync
|
||||||
// start autosync for specified ldap, old existing autosync goroutine will be ceased
|
// start autosync for specified ldap, old existing autosync goroutine will be ceased
|
||||||
func (l *LdapAutoSynchronizer) StartAutoSync(ldapId string) error {
|
func (l *LdapAutoSynchronizer) StartAutoSync(ldapId string) error {
|
||||||
l.Lock()
|
l.Lock()
|
||||||
@ -95,6 +96,7 @@ func (l *LdapAutoSynchronizer) syncRoutine(ldap *Ldap, stopChan chan struct{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LdapAutoSynchronizerStartUpAll
|
||||||
// start all autosync goroutine for existing ldap servers in each organizations
|
// start all autosync goroutine for existing ldap servers in each organizations
|
||||||
func (l *LdapAutoSynchronizer) LdapAutoSynchronizerStartUpAll() {
|
func (l *LdapAutoSynchronizer) LdapAutoSynchronizerStartUpAll() {
|
||||||
organizations := []*Organization{}
|
organizations := []*Organization{}
|
||||||
|
@ -35,6 +35,7 @@ import (
|
|||||||
uuid "github.com/satori/go.uuid"
|
uuid "github.com/satori/go.uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NewSamlResponse
|
||||||
// returns a saml2 response
|
// returns a saml2 response
|
||||||
func NewSamlResponse(user *User, host string, certificate string, destination string, iss string, requestId string, redirectUri []string) (*etree.Element, error) {
|
func NewSamlResponse(user *User, host string, certificate string, destination string, iss string, requestId string, redirectUri []string) (*etree.Element, error) {
|
||||||
samlResponse := &etree.Element{
|
samlResponse := &etree.Element{
|
||||||
@ -113,6 +114,7 @@ func (x X509Key) GetKeyPair() (privateKey *rsa.PrivateKey, cert []byte, err erro
|
|||||||
return privateKey, cert, err
|
return privateKey, cert, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IdpEntityDescriptor
|
||||||
// SAML METADATA
|
// SAML METADATA
|
||||||
type IdpEntityDescriptor struct {
|
type IdpEntityDescriptor struct {
|
||||||
XMLName xml.Name `xml:"EntityDescriptor"`
|
XMLName xml.Name `xml:"EntityDescriptor"`
|
||||||
|
@ -44,7 +44,7 @@ func ParseSamlResponse(samlResponse string, providerType string) (string, error)
|
|||||||
func GenerateSamlLoginUrl(id, relayState string) (string, string, error) {
|
func GenerateSamlLoginUrl(id, relayState string) (string, string, error) {
|
||||||
provider := GetProvider(id)
|
provider := GetProvider(id)
|
||||||
if provider.Category != "SAML" {
|
if provider.Category != "SAML" {
|
||||||
return "", "", fmt.Errorf("Provider %s's category is not SAML", provider.Name)
|
return "", "", fmt.Errorf("provider %s's category is not SAML", provider.Name)
|
||||||
}
|
}
|
||||||
sp, err := buildSp(provider, "")
|
sp, err := buildSp(provider, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -27,14 +27,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
hourSeconds = 3600
|
hourSeconds = 3600
|
||||||
INVALID_REQUEST = "invalid_request"
|
InvalidRequest = "invalid_request"
|
||||||
INVALID_CLIENT = "invalid_client"
|
InvalidClient = "invalid_client"
|
||||||
INVALID_GRANT = "invalid_grant"
|
InvalidGrant = "invalid_grant"
|
||||||
UNAUTHORIZED_CLIENT = "unauthorized_client"
|
UnauthorizedClient = "unauthorized_client"
|
||||||
UNSUPPORTED_GRANT_TYPE = "unsupported_grant_type"
|
UnsupportedGrantType = "unsupported_grant_type"
|
||||||
INVALID_SCOPE = "invalid_scope"
|
InvalidScope = "invalid_scope"
|
||||||
ENDPOINT_ERROR = "endpoint_error"
|
EndpointError = "endpoint_error"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Code struct {
|
type Code struct {
|
||||||
@ -200,7 +200,7 @@ func DeleteToken(token *Token) bool {
|
|||||||
return affected != 0
|
return affected != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteTokenByAceessToken(accessToken string) (bool, *Application) {
|
func DeleteTokenByAccessToken(accessToken string) (bool, *Application) {
|
||||||
token := Token{AccessToken: accessToken}
|
token := Token{AccessToken: accessToken}
|
||||||
existed, err := adapter.Engine.Get(&token)
|
existed, err := adapter.Engine.Get(&token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -325,7 +325,7 @@ func GetOAuthToken(grantType string, clientId string, clientSecret string, code
|
|||||||
application := GetApplicationByClientId(clientId)
|
application := GetApplicationByClientId(clientId)
|
||||||
if application == nil {
|
if application == nil {
|
||||||
return &TokenError{
|
return &TokenError{
|
||||||
Error: INVALID_CLIENT,
|
Error: InvalidClient,
|
||||||
ErrorDescription: "client_id is invalid",
|
ErrorDescription: "client_id is invalid",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -334,7 +334,7 @@ func GetOAuthToken(grantType string, clientId string, clientSecret string, code
|
|||||||
|
|
||||||
if !IsGrantTypeValid(grantType, application.GrantTypes) && tag == "" {
|
if !IsGrantTypeValid(grantType, application.GrantTypes) && tag == "" {
|
||||||
return &TokenError{
|
return &TokenError{
|
||||||
Error: UNSUPPORTED_GRANT_TYPE,
|
Error: UnsupportedGrantType,
|
||||||
ErrorDescription: fmt.Sprintf("grant_type: %s is not supported in this application", grantType),
|
ErrorDescription: fmt.Sprintf("grant_type: %s is not supported in this application", grantType),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -377,20 +377,20 @@ func RefreshToken(grantType string, refreshToken string, scope string, clientId
|
|||||||
// check parameters
|
// check parameters
|
||||||
if grantType != "refresh_token" {
|
if grantType != "refresh_token" {
|
||||||
return &TokenError{
|
return &TokenError{
|
||||||
Error: UNSUPPORTED_GRANT_TYPE,
|
Error: UnsupportedGrantType,
|
||||||
ErrorDescription: "grant_type should be refresh_token",
|
ErrorDescription: "grant_type should be refresh_token",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
application := GetApplicationByClientId(clientId)
|
application := GetApplicationByClientId(clientId)
|
||||||
if application == nil {
|
if application == nil {
|
||||||
return &TokenError{
|
return &TokenError{
|
||||||
Error: INVALID_CLIENT,
|
Error: InvalidClient,
|
||||||
ErrorDescription: "client_id is invalid",
|
ErrorDescription: "client_id is invalid",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if clientSecret != "" && application.ClientSecret != clientSecret {
|
if clientSecret != "" && application.ClientSecret != clientSecret {
|
||||||
return &TokenError{
|
return &TokenError{
|
||||||
Error: INVALID_CLIENT,
|
Error: InvalidClient,
|
||||||
ErrorDescription: "client_secret is invalid",
|
ErrorDescription: "client_secret is invalid",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -399,7 +399,7 @@ func RefreshToken(grantType string, refreshToken string, scope string, clientId
|
|||||||
existed, err := adapter.Engine.Get(&token)
|
existed, err := adapter.Engine.Get(&token)
|
||||||
if err != nil || !existed {
|
if err != nil || !existed {
|
||||||
return &TokenError{
|
return &TokenError{
|
||||||
Error: INVALID_GRANT,
|
Error: InvalidGrant,
|
||||||
ErrorDescription: "refresh token is invalid, expired or revoked",
|
ErrorDescription: "refresh token is invalid, expired or revoked",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -408,7 +408,7 @@ func RefreshToken(grantType string, refreshToken string, scope string, clientId
|
|||||||
_, err = ParseJwtToken(refreshToken, cert)
|
_, err = ParseJwtToken(refreshToken, cert)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &TokenError{
|
return &TokenError{
|
||||||
Error: INVALID_GRANT,
|
Error: InvalidGrant,
|
||||||
ErrorDescription: fmt.Sprintf("parse refresh token error: %s", err.Error()),
|
ErrorDescription: fmt.Sprintf("parse refresh token error: %s", err.Error()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -416,14 +416,14 @@ func RefreshToken(grantType string, refreshToken string, scope string, clientId
|
|||||||
user := getUser(application.Organization, token.User)
|
user := getUser(application.Organization, token.User)
|
||||||
if user.IsForbidden {
|
if user.IsForbidden {
|
||||||
return &TokenError{
|
return &TokenError{
|
||||||
Error: INVALID_GRANT,
|
Error: InvalidGrant,
|
||||||
ErrorDescription: "the user is forbidden to sign in, please contact the administrator",
|
ErrorDescription: "the user is forbidden to sign in, please contact the administrator",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newAccessToken, newRefreshToken, err := generateJwtToken(application, user, "", scope, host)
|
newAccessToken, newRefreshToken, err := generateJwtToken(application, user, "", scope, host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &TokenError{
|
return &TokenError{
|
||||||
Error: ENDPOINT_ERROR,
|
Error: EndpointError,
|
||||||
ErrorDescription: fmt.Sprintf("generate jwt token error: %s", err.Error()),
|
ErrorDescription: fmt.Sprintf("generate jwt token error: %s", err.Error()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -464,6 +464,7 @@ func pkceChallenge(verifier string) string {
|
|||||||
return challenge
|
return challenge
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsGrantTypeValid
|
||||||
// Check if grantType is allowed in the current application
|
// Check if grantType is allowed in the current application
|
||||||
// authorization_code is allowed by default
|
// authorization_code is allowed by default
|
||||||
func IsGrantTypeValid(method string, grantTypes []string) bool {
|
func IsGrantTypeValid(method string, grantTypes []string) bool {
|
||||||
@ -478,11 +479,12 @@ func IsGrantTypeValid(method string, grantTypes []string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetAuthorizationCodeToken
|
||||||
// Authorization code flow
|
// Authorization code flow
|
||||||
func GetAuthorizationCodeToken(application *Application, clientSecret string, code string, verifier string) (*Token, *TokenError) {
|
func GetAuthorizationCodeToken(application *Application, clientSecret string, code string, verifier string) (*Token, *TokenError) {
|
||||||
if code == "" {
|
if code == "" {
|
||||||
return nil, &TokenError{
|
return nil, &TokenError{
|
||||||
Error: INVALID_REQUEST,
|
Error: InvalidRequest,
|
||||||
ErrorDescription: "authorization code should not be empty",
|
ErrorDescription: "authorization code should not be empty",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -490,21 +492,21 @@ func GetAuthorizationCodeToken(application *Application, clientSecret string, co
|
|||||||
token := getTokenByCode(code)
|
token := getTokenByCode(code)
|
||||||
if token == nil {
|
if token == nil {
|
||||||
return nil, &TokenError{
|
return nil, &TokenError{
|
||||||
Error: INVALID_GRANT,
|
Error: InvalidGrant,
|
||||||
ErrorDescription: "authorization code is invalid",
|
ErrorDescription: "authorization code is invalid",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if token.CodeIsUsed {
|
if token.CodeIsUsed {
|
||||||
// anti replay attacks
|
// anti replay attacks
|
||||||
return nil, &TokenError{
|
return nil, &TokenError{
|
||||||
Error: INVALID_GRANT,
|
Error: InvalidGrant,
|
||||||
ErrorDescription: "authorization code has been used",
|
ErrorDescription: "authorization code has been used",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if token.CodeChallenge != "" && pkceChallenge(verifier) != token.CodeChallenge {
|
if token.CodeChallenge != "" && pkceChallenge(verifier) != token.CodeChallenge {
|
||||||
return nil, &TokenError{
|
return nil, &TokenError{
|
||||||
Error: INVALID_GRANT,
|
Error: InvalidGrant,
|
||||||
ErrorDescription: "verifier is invalid",
|
ErrorDescription: "verifier is invalid",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -514,13 +516,13 @@ func GetAuthorizationCodeToken(application *Application, clientSecret string, co
|
|||||||
// but if it is provided, it must be accurate.
|
// but if it is provided, it must be accurate.
|
||||||
if token.CodeChallenge == "" {
|
if token.CodeChallenge == "" {
|
||||||
return nil, &TokenError{
|
return nil, &TokenError{
|
||||||
Error: INVALID_CLIENT,
|
Error: InvalidClient,
|
||||||
ErrorDescription: "client_secret is invalid",
|
ErrorDescription: "client_secret is invalid",
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if clientSecret != "" {
|
if clientSecret != "" {
|
||||||
return nil, &TokenError{
|
return nil, &TokenError{
|
||||||
Error: INVALID_CLIENT,
|
Error: InvalidClient,
|
||||||
ErrorDescription: "client_secret is invalid",
|
ErrorDescription: "client_secret is invalid",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -529,7 +531,7 @@ func GetAuthorizationCodeToken(application *Application, clientSecret string, co
|
|||||||
|
|
||||||
if application.Name != token.Application {
|
if application.Name != token.Application {
|
||||||
return nil, &TokenError{
|
return nil, &TokenError{
|
||||||
Error: INVALID_GRANT,
|
Error: InvalidGrant,
|
||||||
ErrorDescription: "the token is for wrong application (client_id)",
|
ErrorDescription: "the token is for wrong application (client_id)",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -537,39 +539,40 @@ func GetAuthorizationCodeToken(application *Application, clientSecret string, co
|
|||||||
if time.Now().Unix() > token.CodeExpireIn {
|
if time.Now().Unix() > token.CodeExpireIn {
|
||||||
// code must be used within 5 minutes
|
// code must be used within 5 minutes
|
||||||
return nil, &TokenError{
|
return nil, &TokenError{
|
||||||
Error: INVALID_GRANT,
|
Error: InvalidGrant,
|
||||||
ErrorDescription: "authorization code has expired",
|
ErrorDescription: "authorization code has expired",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return token, nil
|
return token, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetPasswordToken
|
||||||
// Resource Owner Password Credentials flow
|
// Resource Owner Password Credentials flow
|
||||||
func GetPasswordToken(application *Application, username string, password string, scope string, host string) (*Token, *TokenError) {
|
func GetPasswordToken(application *Application, username string, password string, scope string, host string) (*Token, *TokenError) {
|
||||||
user := getUser(application.Organization, username)
|
user := getUser(application.Organization, username)
|
||||||
if user == nil {
|
if user == nil {
|
||||||
return nil, &TokenError{
|
return nil, &TokenError{
|
||||||
Error: INVALID_GRANT,
|
Error: InvalidGrant,
|
||||||
ErrorDescription: "the user does not exist",
|
ErrorDescription: "the user does not exist",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
msg := CheckPassword(user, password)
|
msg := CheckPassword(user, password)
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
return nil, &TokenError{
|
return nil, &TokenError{
|
||||||
Error: INVALID_GRANT,
|
Error: InvalidGrant,
|
||||||
ErrorDescription: "invalid username or password",
|
ErrorDescription: "invalid username or password",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if user.IsForbidden {
|
if user.IsForbidden {
|
||||||
return nil, &TokenError{
|
return nil, &TokenError{
|
||||||
Error: INVALID_GRANT,
|
Error: InvalidGrant,
|
||||||
ErrorDescription: "the user is forbidden to sign in, please contact the administrator",
|
ErrorDescription: "the user is forbidden to sign in, please contact the administrator",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
accessToken, refreshToken, err := generateJwtToken(application, user, "", scope, host)
|
accessToken, refreshToken, err := generateJwtToken(application, user, "", scope, host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, &TokenError{
|
return nil, &TokenError{
|
||||||
Error: ENDPOINT_ERROR,
|
Error: EndpointError,
|
||||||
ErrorDescription: fmt.Sprintf("generate jwt token error: %s", err.Error()),
|
ErrorDescription: fmt.Sprintf("generate jwt token error: %s", err.Error()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -592,11 +595,12 @@ func GetPasswordToken(application *Application, username string, password string
|
|||||||
return token, nil
|
return token, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetClientCredentialsToken
|
||||||
// Client Credentials flow
|
// Client Credentials flow
|
||||||
func GetClientCredentialsToken(application *Application, clientSecret string, scope string, host string) (*Token, *TokenError) {
|
func GetClientCredentialsToken(application *Application, clientSecret string, scope string, host string) (*Token, *TokenError) {
|
||||||
if application.ClientSecret != clientSecret {
|
if application.ClientSecret != clientSecret {
|
||||||
return nil, &TokenError{
|
return nil, &TokenError{
|
||||||
Error: INVALID_CLIENT,
|
Error: InvalidClient,
|
||||||
ErrorDescription: "client_secret is invalid",
|
ErrorDescription: "client_secret is invalid",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -608,7 +612,7 @@ func GetClientCredentialsToken(application *Application, clientSecret string, sc
|
|||||||
accessToken, _, err := generateJwtToken(application, nullUser, "", scope, host)
|
accessToken, _, err := generateJwtToken(application, nullUser, "", scope, host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, &TokenError{
|
return nil, &TokenError{
|
||||||
Error: ENDPOINT_ERROR,
|
Error: EndpointError,
|
||||||
ErrorDescription: fmt.Sprintf("generate jwt token error: %s", err.Error()),
|
ErrorDescription: fmt.Sprintf("generate jwt token error: %s", err.Error()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -630,6 +634,7 @@ func GetClientCredentialsToken(application *Application, clientSecret string, sc
|
|||||||
return token, nil
|
return token, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetTokenByUser
|
||||||
// Implicit flow
|
// Implicit flow
|
||||||
func GetTokenByUser(application *Application, user *User, scope string, host string) (*Token, error) {
|
func GetTokenByUser(application *Application, user *User, scope string, host string) (*Token, error) {
|
||||||
accessToken, refreshToken, err := generateJwtToken(application, user, "", scope, host)
|
accessToken, refreshToken, err := generateJwtToken(application, user, "", scope, host)
|
||||||
@ -655,12 +660,13 @@ func GetTokenByUser(application *Application, user *User, scope string, host str
|
|||||||
return token, nil
|
return token, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetWechatMiniProgramToken
|
||||||
// Wechat Mini Program flow
|
// Wechat Mini Program flow
|
||||||
func GetWechatMiniProgramToken(application *Application, code string, host string, username string, avatar string) (*Token, *TokenError) {
|
func GetWechatMiniProgramToken(application *Application, code string, host string, username string, avatar string) (*Token, *TokenError) {
|
||||||
mpProvider := GetWechatMiniProgramProvider(application)
|
mpProvider := GetWechatMiniProgramProvider(application)
|
||||||
if mpProvider == nil {
|
if mpProvider == nil {
|
||||||
return nil, &TokenError{
|
return nil, &TokenError{
|
||||||
Error: INVALID_CLIENT,
|
Error: InvalidClient,
|
||||||
ErrorDescription: "the application does not support wechat mini program",
|
ErrorDescription: "the application does not support wechat mini program",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -669,14 +675,14 @@ func GetWechatMiniProgramToken(application *Application, code string, host strin
|
|||||||
session, err := mpIdp.GetSessionByCode(code)
|
session, err := mpIdp.GetSessionByCode(code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, &TokenError{
|
return nil, &TokenError{
|
||||||
Error: INVALID_GRANT,
|
Error: InvalidGrant,
|
||||||
ErrorDescription: fmt.Sprintf("get wechat mini program session error: %s", err.Error()),
|
ErrorDescription: fmt.Sprintf("get wechat mini program session error: %s", err.Error()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
openId, unionId := session.Openid, session.Unionid
|
openId, unionId := session.Openid, session.Unionid
|
||||||
if openId == "" && unionId == "" {
|
if openId == "" && unionId == "" {
|
||||||
return nil, &TokenError{
|
return nil, &TokenError{
|
||||||
Error: INVALID_REQUEST,
|
Error: InvalidRequest,
|
||||||
ErrorDescription: "the wechat mini program session is invalid",
|
ErrorDescription: "the wechat mini program session is invalid",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -684,7 +690,7 @@ func GetWechatMiniProgramToken(application *Application, code string, host strin
|
|||||||
if user == nil {
|
if user == nil {
|
||||||
if !application.EnableSignUp {
|
if !application.EnableSignUp {
|
||||||
return nil, &TokenError{
|
return nil, &TokenError{
|
||||||
Error: INVALID_GRANT,
|
Error: InvalidGrant,
|
||||||
ErrorDescription: "the application does not allow to sign up new account",
|
ErrorDescription: "the application does not allow to sign up new account",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -710,8 +716,8 @@ func GetWechatMiniProgramToken(application *Application, code string, host strin
|
|||||||
IsForbidden: false,
|
IsForbidden: false,
|
||||||
IsDeleted: false,
|
IsDeleted: false,
|
||||||
Properties: map[string]string{
|
Properties: map[string]string{
|
||||||
USER_PROPERTIES_WECHAT_OPEN_ID: openId,
|
UserPropertiesWechatOpenId: openId,
|
||||||
USER_PROPERTIES_WECHAT_UNION_ID: unionId,
|
UserPropertiesWechatUnionId: unionId,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
AddUser(user)
|
AddUser(user)
|
||||||
@ -720,7 +726,7 @@ func GetWechatMiniProgramToken(application *Application, code string, host strin
|
|||||||
accessToken, refreshToken, err := generateJwtToken(application, user, "", "", host)
|
accessToken, refreshToken, err := generateJwtToken(application, user, "", "", host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, &TokenError{
|
return nil, &TokenError{
|
||||||
Error: ENDPOINT_ERROR,
|
Error: EndpointError,
|
||||||
ErrorDescription: fmt.Sprintf("generate jwt token error: %s", err.Error()),
|
ErrorDescription: fmt.Sprintf("generate jwt token error: %s", err.Error()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,6 +136,7 @@ func GenerateId() {
|
|||||||
panic("unimplemented")
|
panic("unimplemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetCasTokenByPgt
|
||||||
/**
|
/**
|
||||||
@ret1: whether a token is found
|
@ret1: whether a token is found
|
||||||
@ret2: token, nil if not found
|
@ret2: token, nil if not found
|
||||||
@ -150,6 +151,7 @@ func GetCasTokenByPgt(pgt string) (bool, *CasAuthenticationSuccess, string, stri
|
|||||||
return false, nil, "", ""
|
return false, nil, "", ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetCasTokenByTicket
|
||||||
/**
|
/**
|
||||||
@ret1: whether a token is found
|
@ret1: whether a token is found
|
||||||
@ret2: token, nil if not found
|
@ret2: token, nil if not found
|
||||||
@ -207,6 +209,7 @@ func GenerateCasToken(userId string, service string) (string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetValidationBySaml
|
||||||
/**
|
/**
|
||||||
@ret1: saml response
|
@ret1: saml response
|
||||||
@ret2: the service URL who requested to issue this token
|
@ret2: the service URL who requested to issue this token
|
||||||
|
@ -25,8 +25,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
USER_PROPERTIES_WECHAT_UNION_ID = "wechatUnionId"
|
UserPropertiesWechatUnionId = "wechatUnionId"
|
||||||
USER_PROPERTIES_WECHAT_OPEN_ID = "wechatOpenId"
|
UserPropertiesWechatOpenId = "wechatOpenId"
|
||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
|
@ -50,30 +50,31 @@ func GetWebAuthnObject(host string) *webauthn.WebAuthn {
|
|||||||
return webAuthn
|
return webAuthn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WebAuthnID
|
||||||
// implementation of webauthn.User interface
|
// implementation of webauthn.User interface
|
||||||
func (u *User) WebAuthnID() []byte {
|
func (user *User) WebAuthnID() []byte {
|
||||||
return []byte(u.GetId())
|
return []byte(user.GetId())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) WebAuthnName() string {
|
func (user *User) WebAuthnName() string {
|
||||||
return u.Name
|
return user.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) WebAuthnDisplayName() string {
|
func (user *User) WebAuthnDisplayName() string {
|
||||||
return u.DisplayName
|
return user.DisplayName
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) WebAuthnCredentials() []webauthn.Credential {
|
func (user *User) WebAuthnCredentials() []webauthn.Credential {
|
||||||
return u.WebauthnCredentials
|
return user.WebauthnCredentials
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) WebAuthnIcon() string {
|
func (user *User) WebAuthnIcon() string {
|
||||||
return u.Avatar
|
return user.Avatar
|
||||||
}
|
}
|
||||||
|
|
||||||
// CredentialExcludeList returns a CredentialDescriptor array filled with all the user's credentials
|
// CredentialExcludeList returns a CredentialDescriptor array filled with all the user's credentials
|
||||||
func (u *User) CredentialExcludeList() []protocol.CredentialDescriptor {
|
func (user *User) CredentialExcludeList() []protocol.CredentialDescriptor {
|
||||||
credentials := u.WebAuthnCredentials()
|
credentials := user.WebAuthnCredentials()
|
||||||
credentialExcludeList := []protocol.CredentialDescriptor{}
|
credentialExcludeList := []protocol.CredentialDescriptor{}
|
||||||
for _, cred := range credentials {
|
for _, cred := range credentials {
|
||||||
descriptor := protocol.CredentialDescriptor{
|
descriptor := protocol.CredentialDescriptor{
|
||||||
@ -86,16 +87,16 @@ func (u *User) CredentialExcludeList() []protocol.CredentialDescriptor {
|
|||||||
return credentialExcludeList
|
return credentialExcludeList
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) AddCredentials(credential webauthn.Credential, isGlobalAdmin bool) bool {
|
func (user *User) AddCredentials(credential webauthn.Credential, isGlobalAdmin bool) bool {
|
||||||
u.WebauthnCredentials = append(u.WebauthnCredentials, credential)
|
user.WebauthnCredentials = append(user.WebauthnCredentials, credential)
|
||||||
return UpdateUser(u.GetId(), u, []string{"webauthnCredentials"}, isGlobalAdmin)
|
return UpdateUser(user.GetId(), user, []string{"webauthnCredentials"}, isGlobalAdmin)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) DeleteCredentials(credentialIdBase64 string) bool {
|
func (user *User) DeleteCredentials(credentialIdBase64 string) bool {
|
||||||
for i, credential := range u.WebauthnCredentials {
|
for i, credential := range user.WebauthnCredentials {
|
||||||
if base64.StdEncoding.EncodeToString(credential.ID) == credentialIdBase64 {
|
if base64.StdEncoding.EncodeToString(credential.ID) == credentialIdBase64 {
|
||||||
u.WebauthnCredentials = append(u.WebauthnCredentials[0:i], u.WebauthnCredentials[i+1:]...)
|
user.WebauthnCredentials = append(user.WebauthnCredentials[0:i], user.WebauthnCredentials[i+1:]...)
|
||||||
return UpdateUserForAllFields(u.GetId(), u)
|
return UpdateUserForAllFields(user.GetId(), user)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -42,7 +42,7 @@ type VerificationRecord struct {
|
|||||||
|
|
||||||
func SendVerificationCodeToEmail(organization *Organization, user *User, provider *Provider, remoteAddr string, dest string) error {
|
func SendVerificationCodeToEmail(organization *Organization, user *User, provider *Provider, remoteAddr string, dest string) error {
|
||||||
if provider == nil {
|
if provider == nil {
|
||||||
return fmt.Errorf("Please set an Email provider first")
|
return fmt.Errorf("please set an Email provider first")
|
||||||
}
|
}
|
||||||
|
|
||||||
sender := organization.DisplayName
|
sender := organization.DisplayName
|
||||||
@ -60,7 +60,7 @@ func SendVerificationCodeToEmail(organization *Organization, user *User, provide
|
|||||||
|
|
||||||
func SendVerificationCodeToPhone(organization *Organization, user *User, provider *Provider, remoteAddr string, dest string) error {
|
func SendVerificationCodeToPhone(organization *Organization, user *User, provider *Provider, remoteAddr string, dest string) error {
|
||||||
if provider == nil {
|
if provider == nil {
|
||||||
return errors.New("Please set a SMS provider first")
|
return errors.New("please set a SMS provider first")
|
||||||
}
|
}
|
||||||
|
|
||||||
code := getRandomCode(5)
|
code := getRandomCode(5)
|
||||||
@ -85,7 +85,7 @@ func AddToVerificationRecord(user *User, provider *Provider, remoteAddr, recordT
|
|||||||
|
|
||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
if has && now-record.Time < 60 {
|
if has && now-record.Time < 60 {
|
||||||
return errors.New("You can only send one code in 60s.")
|
return errors.New("you can only send one code in 60s")
|
||||||
}
|
}
|
||||||
|
|
||||||
record.Owner = provider.Owner
|
record.Owner = provider.Owner
|
||||||
|
3
pp/gc.go
3
pp/gc.go
@ -20,7 +20,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
@ -147,7 +146,7 @@ func (pp *GcPaymentProvider) doPost(postBytes []byte) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
}(resp.Body)
|
}(resp.Body)
|
||||||
|
|
||||||
respBytes, err := ioutil.ReadAll(resp.Body)
|
respBytes, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -168,7 +168,7 @@ func GetMinLenStr(strs ...string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ReadStringFromPath(path string) string {
|
func ReadStringFromPath(path string) string {
|
||||||
data, err := ioutil.ReadFile(path)
|
data, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -177,7 +177,7 @@ func ReadStringFromPath(path string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func WriteStringToPath(s string, path string) {
|
func WriteStringToPath(s string, path string) {
|
||||||
err := ioutil.WriteFile(path, []byte(s), 0o644)
|
err := os.WriteFile(path, []byte(s), 0o644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user