62 lines
1.3 KiB
Go
62 lines
1.3 KiB
Go
package hydra
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
type Client struct {
|
|
baseURL string
|
|
http *http.Client
|
|
}
|
|
|
|
func (c *Client) LoginRequest(challenge string) (*LoginResponse, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (c *Client) Accept(challenge string) (*AcceptResponse, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (c *Client) RejectRequest(challenge string) (*RejectResponse, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (c *Client) LogoutRequest(challenge string) (*LogoutResponse, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (c *Client) ConsentRequest(challenge string) (*ConsentResponse, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (c *Client) LoginChallenge(r *http.Request) (string, error) {
|
|
return c.challenge(r, "login_challenge")
|
|
}
|
|
|
|
func (c *Client) ConsentChallenge(r *http.Request) (string, error) {
|
|
return c.challenge(r, "consent_challenge")
|
|
}
|
|
|
|
func (c *Client) LogoutChallenge(r *http.Request) (string, error) {
|
|
return c.challenge(r, "logout_challenge")
|
|
}
|
|
|
|
func (c *Client) challenge(r *http.Request, name string) (string, error) {
|
|
challenge := r.URL.Query().Get(name)
|
|
if challenge == "" {
|
|
return "", ErrChallengeNotFound
|
|
}
|
|
|
|
return challenge, nil
|
|
}
|
|
|
|
func NewClient(baseURL string, httpTimeout time.Duration) *Client {
|
|
return &Client{
|
|
baseURL: baseURL,
|
|
http: &http.Client{
|
|
Timeout: 30 * time.Second,
|
|
},
|
|
}
|
|
}
|