goHttpDigestClient

package module
v0.0.0-...-6d28bb1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2017 License: MIT Imports: 7 Imported by: 17

README

go-http-digest-client

Build Status Coverage Status

Library just for http digest auth, and refer RFC-2617

install

get -u -v github.com/Soontao/goHttpDigestClient

usage

func TestClientAuthorize(t *testing.T) {
  req, err := http.NewRequest("GET", testDigestAuthServerURL, nil)
  if err != nil {
    t.Fatal(err)
  }
  opt := &ClientOption{username: testServerUsername, password: testServerPassword}
  res, err := DefaultClient.Do(req, opt)
}

todo

  • if option in Client, only need 1 request get challenge

Documentation

Index

Constants

View Source
const (
	KEY_DIGEST           = "Digest"
	KEY_AUTH_SCHEMA      = "auth_schema"
	KEY_QOP              = "qop"
	KEY_NONCE            = "nonce"
	KEY_CNONCE           = "cnonce"
	KEY_USERNAME         = "username"
	KEY_NONCE_COUNT      = "nc"
	KEY_OPAQUE           = "opaque"
	KEY_RESPONSE         = "response"
	KEY_REALM            = "realm"
	KEY_AUTHORIZATION    = "Authorization"
	KEY_URI              = "uri"
	KEY_WWW_Authenticate = "WWW-Authenticate"
)

Variables

View Source
var DefaultClient = &Client{is_init: true}

static Defualt Client

Functions

func Do

func Do(req *http.Request, opt *ClientOption) (*http.Response, error)

Default Client Do Request

Types

type Challenge

type Challenge map[string]string

The 401 (Unauthorized) response message is used by an origin server to challenge the authorization of a user agent.

And the CHALLENGE will include informations about auth

func GetChallengeFromHeader

func GetChallengeFromHeader(h *http.Header) Challenge

func NewChallenge

func NewChallenge(wwwAuthHeader string) Challenge

func (Challenge) ComputeResponse

func (h Challenge) ComputeResponse(method, uri, entity, username, password string) Challenge

base challenge to compute the response, and the response will be checking by server

func (Challenge) GetChallengeItemFormat

func (info Challenge) GetChallengeItemFormat(itemKey string) string

some specific key, will add qutation mark

func (Challenge) GetChallengeItemPure

func (info Challenge) GetChallengeItemPure(itemKey string) string

func (Challenge) IsDigestAuth

func (info Challenge) IsDigestAuth() bool

func (Challenge) SetChallengeItem

func (info Challenge) SetChallengeItem(itemKey string, itemValue string)

func (Challenge) ToAuthorizationStr

func (info Challenge) ToAuthorizationStr() string

format challenge header to authorization header

MAYBE you should computeResponseFirst()

type Client

type Client struct {
	http.Client
	// contains filtered or unexported fields
}

if option is set, get challenge at construct time if option not set, ever digest auth will send 2 request

func NewClient

func NewClient(username, password string) *Client

create new Client instance

func (*Client) Do

func (c *Client) Do(req *http.Request, opt *ClientOption) (*http.Response, error)

type ClientOption

type ClientOption struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL