chore(style): use gofumpt to fmt go code (#967)

This commit is contained in:
q1anx1 2022-08-07 12:26:14 +08:00 committed by GitHub
parent 45d2745b67
commit 2ea58cd639
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
63 changed files with 172 additions and 188 deletions

View File

@ -31,8 +31,7 @@ import (
const AliyunCaptchaVerifyUrl = "http://afs.aliyuncs.com" const AliyunCaptchaVerifyUrl = "http://afs.aliyuncs.com"
type AliyunCaptchaProvider struct { type AliyunCaptchaProvider struct{}
}
func NewAliyunCaptchaProvider() *AliyunCaptchaProvider { func NewAliyunCaptchaProvider() *AliyunCaptchaProvider {
captcha := &AliyunCaptchaProvider{} captcha := &AliyunCaptchaProvider{}

View File

@ -16,8 +16,7 @@ package captcha
import "github.com/casdoor/casdoor/object" import "github.com/casdoor/casdoor/object"
type DefaultCaptchaProvider struct { type DefaultCaptchaProvider struct{}
}
func NewDefaultCaptchaProvider() *DefaultCaptchaProvider { func NewDefaultCaptchaProvider() *DefaultCaptchaProvider {
captcha := &DefaultCaptchaProvider{} captcha := &DefaultCaptchaProvider{}

View File

@ -28,8 +28,7 @@ import (
const GEETESTCaptchaVerifyUrl = "http://gcaptcha4.geetest.com/validate" const GEETESTCaptchaVerifyUrl = "http://gcaptcha4.geetest.com/validate"
type GEETESTCaptchaProvider struct { type GEETESTCaptchaProvider struct{}
}
func NewGEETESTCaptchaProvider() *GEETESTCaptchaProvider { func NewGEETESTCaptchaProvider() *GEETESTCaptchaProvider {
captcha := &GEETESTCaptchaProvider{} captcha := &GEETESTCaptchaProvider{}

View File

@ -25,8 +25,7 @@ import (
const HCaptchaVerifyUrl = "https://hcaptcha.com/siteverify" const HCaptchaVerifyUrl = "https://hcaptcha.com/siteverify"
type HCaptchaProvider struct { type HCaptchaProvider struct{}
}
func NewHCaptchaProvider() *HCaptchaProvider { func NewHCaptchaProvider() *HCaptchaProvider {
captcha := &HCaptchaProvider{} captcha := &HCaptchaProvider{}

View File

@ -25,8 +25,7 @@ import (
const ReCaptchaVerifyUrl = "https://recaptcha.net/recaptcha/api/siteverify" const ReCaptchaVerifyUrl = "https://recaptcha.net/recaptcha/api/siteverify"
type ReCaptchaProvider struct { type ReCaptchaProvider struct{}
}
func NewReCaptchaProvider() *ReCaptchaProvider { func NewReCaptchaProvider() *ReCaptchaProvider {
captcha := &ReCaptchaProvider{} captcha := &ReCaptchaProvider{}

View File

@ -49,7 +49,7 @@ func GetConfigInt64(key string) (int64, error) {
func init() { func init() {
// this array contains the beego configuration items that may be modified via env // this array contains the beego configuration items that may be modified via env
var presetConfigItems = []string{"httpport", "appname"} presetConfigItems := []string{"httpport", "appname"}
for _, key := range presetConfigItems { for _, key := range presetConfigItems {
if value, ok := os.LookupEnv(key); ok { if value, ok := os.LookupEnv(key); ok {
beego.AppConfig.Set(key, value) beego.AppConfig.Set(key, value)

View File

@ -44,7 +44,6 @@ func tokenToResponse(token *object.Token) *Response {
return &Response{Status: "error", Msg: "fail to get accessToken", Data: token.AccessToken} return &Response{Status: "error", Msg: "fail to get accessToken", Data: token.AccessToken}
} }
return &Response{Status: "ok", Msg: "", Data: token.AccessToken} return &Response{Status: "ok", Msg: "", Data: token.AccessToken}
} }
// HandleLoggedIn ... // HandleLoggedIn ...
@ -94,7 +93,6 @@ func (c *ApiController) HandleLoggedIn(application *object.Application, user *ob
token, _ := object.GetTokenByUser(application, user, scope, c.Ctx.Request.Host) token, _ := object.GetTokenByUser(application, user, scope, c.Ctx.Request.Host)
resp = tokenToResponse(token) resp = tokenToResponse(token)
} }
} else if form.Type == ResponseTypeSaml { // saml flow } else if form.Type == ResponseTypeSaml { // saml flow
res, redirectUrl, err := object.GetSamlResponse(application, user, form.SamlRequest, c.Ctx.Request.Host) res, redirectUrl, err := object.GetSamlResponse(application, user, form.SamlRequest, c.Ctx.Request.Host)
if err != nil { if err != nil {

View File

@ -49,7 +49,6 @@ func (c *RootController) CasValidate() {
c.Ctx.Output.Body([]byte(fmt.Sprintf("yes\n%s\n", response.User))) c.Ctx.Output.Body([]byte(fmt.Sprintf("yes\n%s\n", response.User)))
return return
} }
} }
// token not found // token not found
c.Ctx.Output.Body([]byte("no\n")) c.Ctx.Output.Body([]byte("no\n"))
@ -184,7 +183,6 @@ func (c *RootController) CasProxy() {
c.Data["xml"] = serviceResponse c.Data["xml"] = serviceResponse
c.ServeXML() c.ServeXML()
} }
} }
func (c *RootController) SamlValidate() { func (c *RootController) SamlValidate() {

View File

@ -16,6 +16,7 @@ package controllers
import ( import (
"encoding/json" "encoding/json"
"github.com/astaxie/beego/utils/pagination" "github.com/astaxie/beego/utils/pagination"
"github.com/casdoor/casdoor/object" "github.com/casdoor/casdoor/object"
"github.com/casdoor/casdoor/util" "github.com/casdoor/casdoor/util"

View File

@ -16,6 +16,7 @@ package controllers
import ( import (
"encoding/json" "encoding/json"
"github.com/astaxie/beego/utils/pagination" "github.com/astaxie/beego/utils/pagination"
"github.com/casdoor/casdoor/object" "github.com/casdoor/casdoor/object"
"github.com/casdoor/casdoor/util" "github.com/casdoor/casdoor/util"

View File

@ -24,7 +24,6 @@ func NewArgon2idCredManager() *Argon2idCredManager {
} }
func (cm *Argon2idCredManager) GetHashedPassword(password string, userSalt string, organizationSalt string) string { func (cm *Argon2idCredManager) GetHashedPassword(password string, userSalt string, organizationSalt string) string {
hash, err := argon2id.CreateHash(password, argon2id.DefaultParams) hash, err := argon2id.CreateHash(password, argon2id.DefaultParams)
if err != nil { if err != nil {
return "" return ""

View File

@ -17,6 +17,7 @@ package cred
import ( import (
"crypto/sha256" "crypto/sha256"
"encoding/base64" "encoding/base64"
"golang.org/x/crypto/pbkdf2" "golang.org/x/crypto/pbkdf2"
) )

View File

@ -59,12 +59,12 @@ func (idp *AdfsIdProvider) SetHttpClient(client *http.Client) {
} }
func (idp *AdfsIdProvider) getConfig(hostUrl string) *oauth2.Config { func (idp *AdfsIdProvider) getConfig(hostUrl string) *oauth2.Config {
var endpoint = oauth2.Endpoint{ endpoint := oauth2.Endpoint{
AuthURL: fmt.Sprintf("%s/adfs/oauth2/authorize", hostUrl), AuthURL: fmt.Sprintf("%s/adfs/oauth2/authorize", hostUrl),
TokenURL: fmt.Sprintf("%s/adfs/oauth2/token", hostUrl), TokenURL: fmt.Sprintf("%s/adfs/oauth2/token", hostUrl),
} }
var config = &oauth2.Config{ config := &oauth2.Config{
Endpoint: endpoint, Endpoint: endpoint,
} }

View File

@ -56,12 +56,12 @@ func (idp *AlipayIdProvider) SetHttpClient(client *http.Client) {
// getConfig return a point of Config, which describes a typical 3-legged OAuth2 flow // getConfig return a point of Config, which describes a typical 3-legged OAuth2 flow
func (idp *AlipayIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config { func (idp *AlipayIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config {
var endpoint = oauth2.Endpoint{ endpoint := oauth2.Endpoint{
AuthURL: "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm", AuthURL: "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm",
TokenURL: "https://openapi.alipay.com/gateway.do", TokenURL: "https://openapi.alipay.com/gateway.do",
} }
var config = &oauth2.Config{ config := &oauth2.Config{
Scopes: []string{"", ""}, Scopes: []string{"", ""},
Endpoint: endpoint, Endpoint: endpoint,
ClientID: clientId, ClientID: clientId,
@ -206,7 +206,6 @@ func (idp *AlipayIdProvider) postWithBody(body interface{}, targetUrl string) ([
return nil, err return nil, err
} }
data, err := ioutil.ReadAll(resp.Body) data, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -46,12 +46,12 @@ func (idp *BaiduIdProvider) SetHttpClient(client *http.Client) {
} }
func (idp *BaiduIdProvider) getConfig() *oauth2.Config { func (idp *BaiduIdProvider) getConfig() *oauth2.Config {
var endpoint = oauth2.Endpoint{ endpoint := oauth2.Endpoint{
AuthURL: "https://openapi.baidu.com/oauth/2.0/authorize", AuthURL: "https://openapi.baidu.com/oauth/2.0/authorize",
TokenURL: "https://openapi.baidu.com/oauth/2.0/token", TokenURL: "https://openapi.baidu.com/oauth/2.0/token",
} }
var config = &oauth2.Config{ config := &oauth2.Config{
Scopes: []string{"email"}, Scopes: []string{"email"},
Endpoint: endpoint, Endpoint: endpoint,
} }

View File

@ -47,12 +47,12 @@ func (idp *BilibiliIdProvider) SetHttpClient(client *http.Client) {
// getConfig return a point of Config, which describes a typical 3-legged OAuth2 flow // getConfig return a point of Config, which describes a typical 3-legged OAuth2 flow
func (idp *BilibiliIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config { func (idp *BilibiliIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config {
var endpoint = oauth2.Endpoint{ endpoint := oauth2.Endpoint{
TokenURL: "https://api.bilibili.com/x/account-oauth2/v1/token", TokenURL: "https://api.bilibili.com/x/account-oauth2/v1/token",
AuthURL: "http://member.bilibili.com/arcopen/fn/user/account/info", AuthURL: "http://member.bilibili.com/arcopen/fn/user/account/info",
} }
var config = &oauth2.Config{ config := &oauth2.Config{
Scopes: []string{"", ""}, Scopes: []string{"", ""},
Endpoint: endpoint, Endpoint: endpoint,
ClientID: clientId, ClientID: clientId,
@ -104,7 +104,6 @@ func (idp *BilibiliIdProvider) GetToken(code string) (*oauth2.Token, error) {
} }
data, err := idp.postWithBody(pTokenParams, idp.Config.Endpoint.TokenURL) data, err := idp.postWithBody(pTokenParams, idp.Config.Endpoint.TokenURL)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -167,7 +166,6 @@ func (idp *BilibiliIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, erro
userInfoUrl := fmt.Sprintf("%s?%s", idp.Config.Endpoint.AuthURL, params.Encode()) userInfoUrl := fmt.Sprintf("%s?%s", idp.Config.Endpoint.AuthURL, params.Encode())
resp, err := idp.Client.Get(userInfoUrl) resp, err := idp.Client.Get(userInfoUrl)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -72,7 +72,6 @@ func (idp *CasdoorIdProvider) GetToken(code string) (*oauth2.Token, error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -91,7 +90,6 @@ func (idp *CasdoorIdProvider) GetToken(code string) (*oauth2.Token, error) {
Expiry: time.Unix(time.Now().Unix()+int64(pToken.ExpiresIn), 0), Expiry: time.Unix(time.Now().Unix()+int64(pToken.ExpiresIn), 0),
} }
return token, nil return token, nil
} }
/* /*
@ -155,5 +153,4 @@ func (idp *CasdoorIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error
AvatarUrl: cdUserinfo.AvatarUrl, AvatarUrl: cdUserinfo.AvatarUrl,
} }
return userInfo, nil return userInfo, nil
} }

View File

@ -36,7 +36,7 @@ func NewCustomIdProvider(clientId string, clientSecret string, redirectUrl strin
idp := &CustomIdProvider{} idp := &CustomIdProvider{}
idp.UserInfoUrl = userInfoUrl idp.UserInfoUrl = userInfoUrl
var config = &oauth2.Config{ config := &oauth2.Config{
ClientID: clientId, ClientID: clientId,
ClientSecret: clientSecret, ClientSecret: clientSecret,
RedirectURL: redirectUrl, RedirectURL: redirectUrl,

View File

@ -48,12 +48,12 @@ func (idp *DingTalkIdProvider) SetHttpClient(client *http.Client) {
// getConfig return a point of Config, which describes a typical 3-legged OAuth2 flow // getConfig return a point of Config, which describes a typical 3-legged OAuth2 flow
func (idp *DingTalkIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config { func (idp *DingTalkIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config {
var endpoint = oauth2.Endpoint{ endpoint := oauth2.Endpoint{
AuthURL: "https://api.dingtalk.com/v1.0/contact/users/me", AuthURL: "https://api.dingtalk.com/v1.0/contact/users/me",
TokenURL: "https://api.dingtalk.com/v1.0/oauth2/userAccessToken", TokenURL: "https://api.dingtalk.com/v1.0/oauth2/userAccessToken",
} }
var config = &oauth2.Config{ config := &oauth2.Config{
// DingTalk not allow to set scopes,here it is just a placeholder, // DingTalk not allow to set scopes,here it is just a placeholder,
// convenient to use later // convenient to use later
Scopes: []string{"", ""}, Scopes: []string{"", ""},

View File

@ -42,12 +42,12 @@ func (idp *DouyinIdProvider) SetHttpClient(client *http.Client) {
} }
func (idp *DouyinIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config { func (idp *DouyinIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config {
var endpoint = oauth2.Endpoint{ endpoint := oauth2.Endpoint{
TokenURL: "https://open.douyin.com/oauth/access_token", TokenURL: "https://open.douyin.com/oauth/access_token",
AuthURL: "https://open.douyin.com/platform/oauth/connect", AuthURL: "https://open.douyin.com/platform/oauth/connect",
} }
var config = &oauth2.Config{ config := &oauth2.Config{
Scopes: []string{"user_info"}, Scopes: []string{"user_info"},
Endpoint: endpoint, Endpoint: endpoint,
ClientID: clientId, ClientID: clientId,

View File

@ -46,11 +46,11 @@ func (idp *FacebookIdProvider) SetHttpClient(client *http.Client) {
// getConfig return a point of Config, which describes a typical 3-legged OAuth2 flow // getConfig return a point of Config, which describes a typical 3-legged OAuth2 flow
func (idp *FacebookIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config { func (idp *FacebookIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config {
var endpoint = oauth2.Endpoint{ endpoint := oauth2.Endpoint{
TokenURL: "https://graph.facebook.com/oauth/access_token", TokenURL: "https://graph.facebook.com/oauth/access_token",
} }
var config = &oauth2.Config{ config := &oauth2.Config{
Scopes: []string{"email,public_profile"}, Scopes: []string{"email,public_profile"},
Endpoint: endpoint, Endpoint: endpoint,
ClientID: clientId, ClientID: clientId,

View File

@ -49,11 +49,11 @@ func (idp *GiteeIdProvider) SetHttpClient(client *http.Client) {
// getConfig return a point of Config, which describes a typical 3-legged OAuth2 flow // getConfig return a point of Config, which describes a typical 3-legged OAuth2 flow
func (idp *GiteeIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config { func (idp *GiteeIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config {
var endpoint = oauth2.Endpoint{ endpoint := oauth2.Endpoint{
TokenURL: "https://gitee.com/oauth/token", TokenURL: "https://gitee.com/oauth/token",
} }
var config = &oauth2.Config{ config := &oauth2.Config{
Scopes: []string{"user_info emails"}, Scopes: []string{"user_info emails"},
Endpoint: endpoint, Endpoint: endpoint,

View File

@ -49,12 +49,12 @@ func (idp *GithubIdProvider) SetHttpClient(client *http.Client) {
} }
func (idp *GithubIdProvider) getConfig() *oauth2.Config { func (idp *GithubIdProvider) getConfig() *oauth2.Config {
var endpoint = oauth2.Endpoint{ endpoint := oauth2.Endpoint{
AuthURL: "https://github.com/login/oauth/authorize", AuthURL: "https://github.com/login/oauth/authorize",
TokenURL: "https://github.com/login/oauth/access_token", TokenURL: "https://github.com/login/oauth/access_token",
} }
var config = &oauth2.Config{ config := &oauth2.Config{
Scopes: []string{"user:email", "read:user"}, Scopes: []string{"user:email", "read:user"},
Endpoint: endpoint, Endpoint: endpoint,
} }
@ -93,7 +93,6 @@ func (idp *GithubIdProvider) GetToken(code string) (*oauth2.Token, error) {
} }
return token, nil return token, nil
} }
//{ //{

View File

@ -46,11 +46,11 @@ func (idp *GitlabIdProvider) SetHttpClient(client *http.Client) {
// getConfig return a point of Config, which describes a typical 3-legged OAuth2 flow // getConfig return a point of Config, which describes a typical 3-legged OAuth2 flow
func (idp *GitlabIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config { func (idp *GitlabIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config {
var endpoint = oauth2.Endpoint{ endpoint := oauth2.Endpoint{
TokenURL: "https://gitlab.com/oauth/token", TokenURL: "https://gitlab.com/oauth/token",
} }
var config = &oauth2.Config{ config := &oauth2.Config{
Scopes: []string{"read_user+profile"}, Scopes: []string{"read_user+profile"},
Endpoint: endpoint, Endpoint: endpoint,
ClientID: clientId, ClientID: clientId,

View File

@ -47,12 +47,12 @@ func (idp *GoogleIdProvider) SetHttpClient(client *http.Client) {
} }
func (idp *GoogleIdProvider) getConfig() *oauth2.Config { func (idp *GoogleIdProvider) getConfig() *oauth2.Config {
var endpoint = oauth2.Endpoint{ endpoint := oauth2.Endpoint{
AuthURL: "https://accounts.google.com/o/oauth2/auth", AuthURL: "https://accounts.google.com/o/oauth2/auth",
TokenURL: "https://accounts.google.com/o/oauth2/token", TokenURL: "https://accounts.google.com/o/oauth2/token",
} }
var config = &oauth2.Config{ config := &oauth2.Config{
Scopes: []string{"profile", "email"}, Scopes: []string{"profile", "email"},
Endpoint: endpoint, Endpoint: endpoint,
} }

View File

@ -43,7 +43,7 @@ func (idp *InfoflowInternalIdProvider) SetHttpClient(client *http.Client) {
} }
func (idp *InfoflowInternalIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config { func (idp *InfoflowInternalIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config {
var config = &oauth2.Config{ config := &oauth2.Config{
ClientID: clientId, ClientID: clientId,
ClientSecret: clientSecret, ClientSecret: clientSecret,
RedirectURL: redirectUrl, RedirectURL: redirectUrl,

View File

@ -47,7 +47,7 @@ func (idp *InfoflowIdProvider) SetHttpClient(client *http.Client) {
} }
func (idp *InfoflowIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config { func (idp *InfoflowIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config {
var config = &oauth2.Config{ config := &oauth2.Config{
ClientID: clientId, ClientID: clientId,
ClientSecret: clientSecret, ClientSecret: clientSecret,
RedirectURL: redirectUrl, RedirectURL: redirectUrl,

View File

@ -45,11 +45,11 @@ func (idp *LarkIdProvider) SetHttpClient(client *http.Client) {
// getConfig return a point of Config, which describes a typical 3-legged OAuth2 flow // getConfig return a point of Config, which describes a typical 3-legged OAuth2 flow
func (idp *LarkIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config { func (idp *LarkIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config {
var endpoint = oauth2.Endpoint{ endpoint := oauth2.Endpoint{
TokenURL: "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal", TokenURL: "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal",
} }
var config = &oauth2.Config{ config := &oauth2.Config{
Scopes: []string{}, Scopes: []string{},
Endpoint: endpoint, Endpoint: endpoint,
ClientID: clientId, ClientID: clientId,

View File

@ -47,11 +47,11 @@ func (idp *LinkedInIdProvider) SetHttpClient(client *http.Client) {
// getConfig return a point of Config, which describes a typical 3-legged OAuth2 flow // getConfig return a point of Config, which describes a typical 3-legged OAuth2 flow
func (idp *LinkedInIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config { func (idp *LinkedInIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config {
var endpoint = oauth2.Endpoint{ endpoint := oauth2.Endpoint{
TokenURL: "https://www.linkedIn.com/oauth/v2/accessToken", TokenURL: "https://www.linkedIn.com/oauth/v2/accessToken",
} }
var config = &oauth2.Config{ config := &oauth2.Config{
Scopes: []string{"email,public_profile"}, Scopes: []string{"email,public_profile"},
Endpoint: endpoint, Endpoint: endpoint,
ClientID: clientId, ClientID: clientId,

View File

@ -48,12 +48,12 @@ func (idp *OktaIdProvider) SetHttpClient(client *http.Client) {
} }
func (idp *OktaIdProvider) getConfig(hostUrl string, clientId string, clientSecret string, redirectUrl string) *oauth2.Config { func (idp *OktaIdProvider) getConfig(hostUrl string, clientId string, clientSecret string, redirectUrl string) *oauth2.Config {
var endpoint = oauth2.Endpoint{ endpoint := oauth2.Endpoint{
TokenURL: fmt.Sprintf("%s/v1/token", hostUrl), TokenURL: fmt.Sprintf("%s/v1/token", hostUrl),
AuthURL: fmt.Sprintf("%s/v1/authorize", hostUrl), AuthURL: fmt.Sprintf("%s/v1/authorize", hostUrl),
} }
var config = &oauth2.Config{ config := &oauth2.Config{
// openid is required for authentication requests // openid is required for authentication requests
// get more details via: https://developer.okta.com/docs/reference/api/oidc/#reserved-scopes // get more details via: https://developer.okta.com/docs/reference/api/oidc/#reserved-scopes
Scopes: []string{"openid", "profile", "email"}, Scopes: []string{"openid", "profile", "email"},

View File

@ -48,11 +48,11 @@ func (idp *QqIdProvider) SetHttpClient(client *http.Client) {
} }
func (idp *QqIdProvider) getConfig() *oauth2.Config { func (idp *QqIdProvider) getConfig() *oauth2.Config {
var endpoint = oauth2.Endpoint{ endpoint := oauth2.Endpoint{
TokenURL: "https://graph.qq.com/oauth2.0/token", TokenURL: "https://graph.qq.com/oauth2.0/token",
} }
var config = &oauth2.Config{ config := &oauth2.Config{
Scopes: []string{"get_user_info"}, Scopes: []string{"get_user_info"},
Endpoint: endpoint, Endpoint: endpoint,
} }

View File

@ -47,11 +47,11 @@ func (idp *WeChatIdProvider) SetHttpClient(client *http.Client) {
// getConfig return a point of Config, which describes a typical 3-legged OAuth2 flow // getConfig return a point of Config, which describes a typical 3-legged OAuth2 flow
func (idp *WeChatIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config { func (idp *WeChatIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config {
var endpoint = oauth2.Endpoint{ endpoint := oauth2.Endpoint{
TokenURL: "https://graph.qq.com/oauth2.0/token", TokenURL: "https://graph.qq.com/oauth2.0/token",
} }
var config = &oauth2.Config{ config := &oauth2.Config{
Scopes: []string{"snsapi_login"}, Scopes: []string{"snsapi_login"},
Endpoint: endpoint, Endpoint: endpoint,
ClientID: clientId, ClientID: clientId,

View File

@ -42,7 +42,7 @@ func (idp *WeChatMiniProgramIdProvider) SetHttpClient(client *http.Client) {
} }
func (idp *WeChatMiniProgramIdProvider) getConfig(clientId string, clientSecret string) *oauth2.Config { func (idp *WeChatMiniProgramIdProvider) getConfig(clientId string, clientSecret string) *oauth2.Config {
var config = &oauth2.Config{ config := &oauth2.Config{
ClientID: clientId, ClientID: clientId,
ClientSecret: clientSecret, ClientSecret: clientSecret,
} }
@ -78,5 +78,4 @@ func (idp *WeChatMiniProgramIdProvider) GetSessionByCode(code string) (*WeChatMi
return nil, fmt.Errorf("err: %s", session.Errmsg) return nil, fmt.Errorf("err: %s", session.Errmsg)
} }
return &session, nil return &session, nil
} }

View File

@ -44,7 +44,7 @@ func (idp *WeComInternalIdProvider) SetHttpClient(client *http.Client) {
} }
func (idp *WeComInternalIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config { func (idp *WeComInternalIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config {
var config = &oauth2.Config{ config := &oauth2.Config{
ClientID: clientId, ClientID: clientId,
ClientSecret: clientSecret, ClientSecret: clientSecret,
RedirectURL: redirectUrl, RedirectURL: redirectUrl,

View File

@ -46,11 +46,11 @@ func (idp *WeComIdProvider) SetHttpClient(client *http.Client) {
// getConfig return a point of Config, which describes a typical 3-legged OAuth2 flow // getConfig return a point of Config, which describes a typical 3-legged OAuth2 flow
func (idp *WeComIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config { func (idp *WeComIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config {
var endpoint = oauth2.Endpoint{ endpoint := oauth2.Endpoint{
TokenURL: "https://graph.qq.com/oauth2.0/token", TokenURL: "https://graph.qq.com/oauth2.0/token",
} }
var config = &oauth2.Config{ config := &oauth2.Config{
Scopes: []string{"snsapi_login"}, Scopes: []string{"snsapi_login"},
Endpoint: endpoint, Endpoint: endpoint,
ClientID: clientId, ClientID: clientId,

View File

@ -48,11 +48,11 @@ func (idp *WeiBoIdProvider) SetHttpClient(client *http.Client) {
// getConfig return a point of Config, which describes a typical 3-legged OAuth2 flow // getConfig return a point of Config, which describes a typical 3-legged OAuth2 flow
func (idp *WeiBoIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config { func (idp *WeiBoIdProvider) getConfig(clientId string, clientSecret string, redirectUrl string) *oauth2.Config {
var endpoint = oauth2.Endpoint{ endpoint := oauth2.Endpoint{
TokenURL: "https://api.weibo.com/oauth2/access_token", TokenURL: "https://api.weibo.com/oauth2/access_token",
} }
var config = &oauth2.Config{ config := &oauth2.Config{
Scopes: []string{""}, Scopes: []string{""},
Endpoint: endpoint, Endpoint: endpoint,
ClientID: clientId, ClientID: clientId,

View File

@ -317,7 +317,7 @@ func (application *Application) GetId() string {
} }
func CheckRedirectUriValid(application *Application, redirectUri string) bool { func CheckRedirectUriValid(application *Application, redirectUri string) bool {
var validUri = false validUri := false
for _, tmpUri := range application.RedirectUris { for _, tmpUri := range application.RedirectUris {
if strings.Contains(redirectUri, tmpUri) { if strings.Contains(redirectUri, tmpUri) {
validUri = true validUri = true

View File

@ -208,11 +208,15 @@ func GetLdapConn(host string, port int, adminUser string, adminPasswd string) (*
func (l *ldapConn) GetLdapUsers(baseDn string) ([]ldapUser, error) { func (l *ldapConn) GetLdapUsers(baseDn string) ([]ldapUser, error) {
SearchFilter := "(objectClass=posixAccount)" SearchFilter := "(objectClass=posixAccount)"
SearchAttributes := []string{"uidNumber", "uid", "cn", "gidNumber", "entryUUID", "mail", "email", SearchAttributes := []string{
"emailAddress", "telephoneNumber", "mobile", "mobileTelephoneNumber", "registeredAddress", "postalAddress"} "uidNumber", "uid", "cn", "gidNumber", "entryUUID", "mail", "email",
"emailAddress", "telephoneNumber", "mobile", "mobileTelephoneNumber", "registeredAddress", "postalAddress",
}
SearchFilterMsAD := "(objectClass=user)" SearchFilterMsAD := "(objectClass=user)"
SearchAttributesMsAD := []string{"uidNumber", "sAMAccountName", "cn", "gidNumber", "entryUUID", "mail", "email", SearchAttributesMsAD := []string{
"emailAddress", "telephoneNumber", "mobile", "mobileTelephoneNumber", "registeredAddress", "postalAddress"} "uidNumber", "sAMAccountName", "cn", "gidNumber", "entryUUID", "mail", "email",
"emailAddress", "telephoneNumber", "mobile", "mobileTelephoneNumber", "registeredAddress", "postalAddress",
}
var searchReq *goldap.SearchRequest var searchReq *goldap.SearchRequest
if l.IsAD { if l.IsAD {
searchReq = goldap.NewSearchRequest(baseDn, searchReq = goldap.NewSearchRequest(baseDn,
@ -459,7 +463,7 @@ func CheckLdapUuidExist(owner string, uuids []string) []string {
} }
} }
for uuid, _ := range existUuidSet { for uuid := range existUuidSet {
existUuids = append(existUuids, uuid) existUuids = append(existUuids, uuid)
} }
return existUuids return existUuids

View File

@ -93,7 +93,6 @@ func (l *LdapAutoSynchronizer) syncRoutine(ldap *Ldap, stopChan chan struct{}) {
logs.Info(fmt.Sprintf("ldap autosync success, %d new users, %d existing users", len(users)-len(*existed), len(*existed))) logs.Info(fmt.Sprintf("ldap autosync success, %d new users, %d existing users", len(users)-len(*existed), len(*existed)))
} }
} }
} }
// start all autosync goroutine for existing ldap servers in each organizations // start all autosync goroutine for existing ldap servers in each organizations

View File

@ -100,7 +100,6 @@ func NewSamlResponse(user *User, host string, certificate string, destination st
displayName.CreateElement("saml:AttributeValue").CreateAttr("xsi:type", "xs:string").Element().SetText(user.DisplayName) displayName.CreateElement("saml:AttributeValue").CreateAttr("xsi:type", "xs:string").Element().SetText(user.DisplayName)
return samlResponse, nil return samlResponse, nil
} }
type X509Key struct { type X509Key struct {

View File

@ -262,7 +262,6 @@ func GetValidationBySaml(samlRequest string, host string) (string, string, error
return "", "", fmt.Errorf("err: %s", err.Error()) return "", "", fmt.Errorf("err: %s", err.Error())
} }
return xmlStr, service, nil return xmlStr, service, nil
} }
func (c *CasAuthenticationSuccess) DeepCopy() CasAuthenticationSuccess { func (c *CasAuthenticationSuccess) DeepCopy() CasAuthenticationSuccess {
@ -307,7 +306,6 @@ func (c *CasAttributes) DeepCopy() CasAttributes {
res.ExtraAttributes[i] = &tmp res.ExtraAttributes[i] = &tmp
} }
return res return res
} }
func (c *CasUserAttributes) DeepCopy() CasUserAttributes { func (c *CasUserAttributes) DeepCopy() CasUserAttributes {
@ -316,11 +314,11 @@ func (c *CasUserAttributes) DeepCopy() CasUserAttributes {
Attributes: make([]*CasNamedAttribute, len(c.Attributes)), Attributes: make([]*CasNamedAttribute, len(c.Attributes)),
} }
for i, a := range c.AnyAttributes { for i, a := range c.AnyAttributes {
var tmp = *a tmp := *a
res.AnyAttributes[i] = &tmp res.AnyAttributes[i] = &tmp
} }
for i, a := range c.Attributes { for i, a := range c.Attributes {
var tmp = *a tmp := *a
res.Attributes[i] = &tmp res.Attributes[i] = &tmp
} }
return res return res

View File

@ -25,8 +25,10 @@ import (
"golang.org/x/net/proxy" "golang.org/x/net/proxy"
) )
var DefaultHttpClient *http.Client var (
var ProxyHttpClient *http.Client DefaultHttpClient *http.Client
ProxyHttpClient *http.Client
)
func InitHttpClient() { func InitHttpClient() {
// not use proxy // not use proxy

View File

@ -71,5 +71,4 @@ func AutoSigninFilter(ctx *context.Context) {
setSessionUser(ctx, userId) setSessionUser(ctx, userId)
return return
} }
} }

View File

@ -30,8 +30,7 @@ func init() {
} }
func initAPI() { func initAPI() {
ns := ns := beego.NewNamespace("/",
beego.NewNamespace("/",
beego.NSNamespace("/api", beego.NSNamespace("/api",
beego.NSInclude( beego.NSInclude(
&controllers.ApiController{}, &controllers.ApiController{},
@ -195,5 +194,4 @@ func initAPI() {
beego.Router("/api/webauthn/signup/finish", &controllers.ApiController{}, "Post:WebAuthnSignupFinish") beego.Router("/api/webauthn/signup/finish", &controllers.ApiController{}, "Post:WebAuthnSignupFinish")
beego.Router("/api/webauthn/signin/begin", &controllers.ApiController{}, "Get:WebAuthnSigninBegin") beego.Router("/api/webauthn/signin/begin", &controllers.ApiController{}, "Get:WebAuthnSigninBegin")
beego.Router("/api/webauthn/signin/finish", &controllers.ApiController{}, "Post:WebAuthnSigninFinish") beego.Router("/api/webauthn/signin/finish", &controllers.ApiController{}, "Post:WebAuthnSigninFinish")
} }

View File

@ -19,8 +19,10 @@ import (
"regexp" "regexp"
) )
var rePhoneCn *regexp.Regexp var (
var rePhone *regexp.Regexp rePhoneCn *regexp.Regexp
rePhone *regexp.Regexp
)
func init() { func init() {
// https://learnku.com/articles/31543 // https://learnku.com/articles/31543

View File

@ -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), 0644) err := ioutil.WriteFile(path, []byte(s), 0o644)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -15,9 +15,10 @@
package util package util
import ( import (
"testing"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"testing"
) )
func TestParseInt(t *testing.T) { func TestParseInt(t *testing.T) {
@ -245,4 +246,3 @@ func TestSnakeString(t *testing.T) {
}) })
} }
} }

View File

@ -31,7 +31,6 @@ func Test_GetCurrentTime(t *testing.T) {
types := reflect.TypeOf(test).Kind() types := reflect.TypeOf(test).Kind()
assert.Equal(t, types, reflect.String, "GetCurrentUnixTime should be return string") assert.Equal(t, types, reflect.String, "GetCurrentUnixTime should be return string")
} }
func Test_GetCurrentUnixTime_Shoud_Return_String(t *testing.T) { func Test_GetCurrentUnixTime_Shoud_Return_String(t *testing.T) {
@ -41,7 +40,6 @@ func Test_GetCurrentUnixTime_Shoud_Return_String(t *testing.T) {
} }
func Test_IsTokenExpired(t *testing.T) { func Test_IsTokenExpired(t *testing.T) {
type input struct { type input struct {
createdTime string createdTime string
expiresIn int expiresIn int