remove AuthClient

This commit is contained in:
aler9
2020-07-13 08:23:09 +02:00
parent 5f7ef9a66c
commit df2da058e0
3 changed files with 11 additions and 11 deletions

14
auth.go
View File

@@ -179,9 +179,9 @@ func (as *AuthServer) ValidateHeader(header []string, method Method, ur *url.URL
return nil return nil
} }
// AuthClient is an object that helps a client to send its credentials to a // authClient is an object that helps a client to send its credentials to a
// server. // server.
type AuthClient struct { type authClient struct {
user string user string
pass string pass string
method AuthMethod method AuthMethod
@@ -189,9 +189,9 @@ type AuthClient struct {
nonce string nonce string
} }
// NewAuthClient allocates an AuthClient. // newAuthClient allocates an authClient.
// header is the WWW-Authenticate header provided by the server. // header is the WWW-Authenticate header provided by the server.
func NewAuthClient(header []string, user string, pass string) (*AuthClient, error) { func newAuthClient(header []string, user string, pass string) (*authClient, error) {
// prefer digest // prefer digest
headerAuthDigest := func() string { headerAuthDigest := func() string {
for _, v := range header { for _, v := range header {
@@ -217,7 +217,7 @@ func NewAuthClient(header []string, user string, pass string) (*AuthClient, erro
return nil, fmt.Errorf("nonce not provided") return nil, fmt.Errorf("nonce not provided")
} }
return &AuthClient{ return &authClient{
user: user, user: user,
pass: pass, pass: pass,
method: Digest, method: Digest,
@@ -245,7 +245,7 @@ func NewAuthClient(header []string, user string, pass string) (*AuthClient, erro
return nil, fmt.Errorf("realm not provided") return nil, fmt.Errorf("realm not provided")
} }
return &AuthClient{ return &authClient{
user: user, user: user,
pass: pass, pass: pass,
method: Basic, method: Basic,
@@ -258,7 +258,7 @@ func NewAuthClient(header []string, user string, pass string) (*AuthClient, erro
// GenerateHeader generates an Authorization Header that allows to authenticate a request with // GenerateHeader generates an Authorization Header that allows to authenticate a request with
// the given method and url. // the given method and url.
func (ac *AuthClient) GenerateHeader(method Method, ur *url.URL) []string { func (ac *authClient) GenerateHeader(method Method, ur *url.URL) []string {
switch ac.method { switch ac.method {
case Basic: case Basic:
response := base64.StdEncoding.EncodeToString([]byte(ac.user + ":" + ac.pass)) response := base64.StdEncoding.EncodeToString([]byte(ac.user + ":" + ac.pass))

View File

@@ -31,7 +31,7 @@ func TestAuthMethods(t *testing.T) {
authServer := NewAuthServer("testuser", "testpass", c.methods) authServer := NewAuthServer("testuser", "testpass", c.methods)
wwwAuthenticate := authServer.GenerateHeader() wwwAuthenticate := authServer.GenerateHeader()
ac, err := NewAuthClient(wwwAuthenticate, "testuser", "testpass") ac, err := newAuthClient(wwwAuthenticate, "testuser", "testpass")
require.NoError(t, err) require.NoError(t, err)
authorization := ac.GenerateHeader(ANNOUNCE, authorization := ac.GenerateHeader(ANNOUNCE,
&url.URL{Scheme: "rtsp", Host: "myhost", Path: "mypath"}) &url.URL{Scheme: "rtsp", Host: "myhost", Path: "mypath"})
@@ -47,7 +47,7 @@ func TestAuthBasePath(t *testing.T) {
authServer := NewAuthServer("testuser", "testpass", []AuthMethod{Basic, Digest}) authServer := NewAuthServer("testuser", "testpass", []AuthMethod{Basic, Digest})
wwwAuthenticate := authServer.GenerateHeader() wwwAuthenticate := authServer.GenerateHeader()
ac, err := NewAuthClient(wwwAuthenticate, "testuser", "testpass") ac, err := newAuthClient(wwwAuthenticate, "testuser", "testpass")
require.NoError(t, err) require.NoError(t, err)
authorization := ac.GenerateHeader(ANNOUNCE, authorization := ac.GenerateHeader(ANNOUNCE,
&url.URL{Scheme: "rtsp", Host: "myhost", Path: "mypath/"}) &url.URL{Scheme: "rtsp", Host: "myhost", Path: "mypath/"})

View File

@@ -45,7 +45,7 @@ type ConnClient struct {
bw *bufio.Writer bw *bufio.Writer
session string session string
curCSeq int curCSeq int
auth *AuthClient auth *authClient
} }
// NewConnClient allocates a ConnClient. See ConnClientConf for the options. // NewConnClient allocates a ConnClient. See ConnClientConf for the options.
@@ -149,7 +149,7 @@ func (c *ConnClient) Do(req *Request) (*Response, error) {
// setup authentication // setup authentication
if res.StatusCode == StatusUnauthorized && req.Url.User != nil && c.auth == nil { if res.StatusCode == StatusUnauthorized && req.Url.User != nil && c.auth == nil {
pass, _ := req.Url.User.Password() pass, _ := req.Url.User.Password()
auth, err := NewAuthClient(res.Header["WWW-Authenticate"], req.Url.User.Username(), pass) auth, err := newAuthClient(res.Header["WWW-Authenticate"], req.Url.User.Username(), pass)
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to setup authentication: %s", err) return nil, fmt.Errorf("unable to setup authentication: %s", err)
} }