mirror of
https://github.com/weloe/token-go.git
synced 2025-10-30 10:27:00 +08:00
feat: support SSO
This commit is contained in:
64
sso/sso_dispatcher_api.go
Normal file
64
sso/sso_dispatcher_api.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package sso
|
||||
|
||||
import (
|
||||
"github.com/weloe/token-go/ctx"
|
||||
"github.com/weloe/token-go/model"
|
||||
)
|
||||
|
||||
/**
|
||||
=========dispatcher api
|
||||
*/
|
||||
|
||||
// ServerDisPatcher dispatcher SSO-Server api, returns model.Result or string.
|
||||
func (s *SsoEnforcer) ServerDisPatcher(ctx ctx.Context) interface{} {
|
||||
request := ctx.Request()
|
||||
apiName := s.apiName
|
||||
path := request.Path()
|
||||
var res interface{}
|
||||
var err error
|
||||
if path == apiName.SsoAuth {
|
||||
res, err = s.SsoAuth(ctx)
|
||||
} else if path == apiName.SsoDoLogin {
|
||||
res, err = s.SsoDoLogin(ctx)
|
||||
} else if path == apiName.SsoCheckTicket && s.config.IsHttp {
|
||||
res, err = s.SsoCheckTicket(ctx)
|
||||
} else if path == apiName.SsoSignout {
|
||||
res, err = s.SsoSignOut(ctx)
|
||||
} else {
|
||||
return model.Error().SetMsg("not handle")
|
||||
}
|
||||
if err != nil {
|
||||
return model.Error().SetMsg(err.Error())
|
||||
}
|
||||
if res == nil {
|
||||
return model.Ok()
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
// ClientDispatcher dispatcher Client api, returns model.Result or string.
|
||||
func (s *SsoEnforcer) ClientDispatcher(ctx ctx.Context) interface{} {
|
||||
request := ctx.Request()
|
||||
apiName := s.apiName
|
||||
path := request.Path()
|
||||
var res interface{}
|
||||
var err error
|
||||
|
||||
if path == apiName.SsoLogin {
|
||||
res, err = s.SsoClientLogin(ctx)
|
||||
} else if path == apiName.SsoLogout {
|
||||
res, err = s.SsoClientLogout(ctx)
|
||||
} else if path == apiName.SsoLogoutCall && s.config.IsSlo && s.config.IsHttp {
|
||||
res, err = s.SsoClientLogoutCall(ctx)
|
||||
} else {
|
||||
return model.Error().SetMsg("not handle")
|
||||
}
|
||||
if err != nil {
|
||||
return model.Error().SetMsg(err.Error())
|
||||
}
|
||||
if res == nil {
|
||||
return model.Ok()
|
||||
}
|
||||
return res
|
||||
}
|
||||
Reference in New Issue
Block a user