打通sso到wayne登陆的全流程
This commit is contained in:
@@ -53,6 +53,13 @@ func (s *WayenService) Login(email, username string) (*WayenLoginResult, error)
|
||||
if email == "" {
|
||||
return nil, ErrWayenEmailMissing
|
||||
}
|
||||
if strings.TrimSpace(s.cfg.OAuthRedirectURI) != "" && strings.TrimSpace(s.cfg.WayenTargetURL) != "" {
|
||||
target, err := s.oauthLoginURL(s.cfg.OAuthRedirectURI, s.cfg.WayenTargetURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &WayenLoginResult{TargetURL: target}, nil
|
||||
}
|
||||
if strings.TrimSpace(s.cfg.WayenLoginURL) == "" || strings.TrimSpace(s.cfg.WayenTargetURL) == "" {
|
||||
return nil, ErrWayenNotConfigured
|
||||
}
|
||||
@@ -100,6 +107,28 @@ func (s *WayenService) Login(email, username string) (*WayenLoginResult, error)
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *WayenService) oauthLoginURL(redirectURI, targetURL string) (string, error) {
|
||||
parsed, err := url.Parse(strings.TrimSpace(redirectURI))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
next, err := url.Parse(strings.TrimSpace(targetURL))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if next.Path == "" || next.Path == "/" {
|
||||
next.Path = "/sign-in"
|
||||
}
|
||||
values := next.Query()
|
||||
values.Set("ref", "oauth")
|
||||
next.RawQuery = values.Encode()
|
||||
|
||||
query := parsed.Query()
|
||||
query.Set("next", next.String())
|
||||
parsed.RawQuery = query.Encode()
|
||||
return parsed.String(), nil
|
||||
}
|
||||
|
||||
func (s *WayenService) loginRequest(loginURL, email, password string) (string, io.Reader, string, error) {
|
||||
usernameKey := defaultConfigValue(s.cfg.WayenUsernameKey, "email")
|
||||
passwordKey := defaultConfigValue(s.cfg.WayenPasswordKey, "password")
|
||||
|
||||
Reference in New Issue
Block a user