1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-25 17:18:05 +08:00

opt oauth

This commit is contained in:
harveyshao 2022-04-14 09:43:50 +08:00
parent 46d61e4f56
commit afd68e0c0b
4 changed files with 11 additions and 8 deletions

View File

@ -352,7 +352,7 @@ func init() {
_spide_create(m, m.Option(mdb.NAME), m.Option(ADDRESS))
}},
"merge": {Name: "merge name path", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
m.Echo(kit.MergeURL(m.Cmd(SPIDE, arg[0]).Append("client.url")+arg[1], arg[2:]))
m.Echo(kit.MergeURL(m.Cmd(SPIDE, arg[0], ice.OptionFields("")).Append("client.url")+arg[1], arg[2:]))
}},
}, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) < 2 || arg[0] == "" || (len(arg) > 3 && arg[3] == "") {

View File

@ -24,9 +24,7 @@ func init() {
}, Commands: map[string]*ice.Command{
OAUTH: {Name: "oauth hash auto", Help: "授权", Action: ice.MergeAction(map[string]*ice.Action{
"config": {Name: "config client_id client_secret redirect_uri", Help: "配置", Hand: func(m *ice.Message, arg ...string) {
m.Config(CLIENT_ID, m.Option(CLIENT_ID))
m.Config(CLIENT_SECRET, m.Option(CLIENT_SECRET))
m.Config(REDIRECT_URI, m.Option(REDIRECT_URI))
m.ConfigOption(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI)
}},
"user": {Name: "user", Help: "用户", Hand: func(m *ice.Message, arg ...string) {
m.Option(web.SPIDE_HEADER, "Accept", web.ContentJSON, "Authorization", "token "+m.Option(ACCESS_TOKEN))
@ -40,7 +38,7 @@ func init() {
}},
}, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if mdb.HashSelect(m, arg...).PushAction("user", ACCESS_TOKEN, mdb.REMOVE); len(arg) == 0 {
m.EchoAnchor(kit.MergeURL2(LOGIN_OAUTH, "authorize", m.ConfigSimple(REDIRECT_URI, CLIENT_ID)))
m.Echo(kit.MergeURL2(LOGIN_OAUTH, "authorize", m.ConfigSimple(REDIRECT_URI, CLIENT_ID)))
}
}},
"/oauth": {Name: "/oauth", Help: "授权", Action: ice.MergeAction(map[string]*ice.Action{}, ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {

View File

@ -42,6 +42,11 @@ func (m *Message) ConfigSimple(key ...string) (list []string) {
}
return
}
func (m *Message) ConfigOption(key ...string) {
for _, k := range kit.Split(kit.Join(key, FS)) {
m.Config(k, kit.Select(m.Config(k), m.Option(k)))
}
}
func (m *Message) Save(arg ...string) *Message {
if len(arg) == 0 {
for k := range m.target.Configs {

View File

@ -456,7 +456,7 @@ func (m *Message) Search(key string, cb interface{}) *Message {
break
}
for _, p := range []*Context{m.target, p, m.source} {
for _, p := range []*Context{p, m.target, m.source} {
for s := p; s != nil; s = s.context {
if cmd, ok := s.Configs[key]; ok {
cb(s.context, s, key, cmd) // 查找配置
@ -508,9 +508,9 @@ func (m *Message) Confv(arg ...interface{}) (val interface{}) { // key sub val
}
key := kit.Format(arg[0])
if conf, ok := m.target.Configs[strings.TrimPrefix(key, m.target.Cap(CTX_FOLLOW)+PT)]; ok {
if conf, ok := m.target.Configs[key]; ok {
run(conf)
} else if conf, ok := m.source.Configs[strings.TrimPrefix(key, m.source.Cap(CTX_FOLLOW)+PT)]; ok {
} else if conf, ok := m.source.Configs[key]; ok {
run(conf)
} else {
m.Search(key, func(p *Context, s *Context, key string, conf *Config) { run(conf) })