// Authorize authorizes the request, first checking the required bearer token and then, if the bearer token was not
// provided, the HTTP signature.
Authorize authorizes the request, first checking the required bearer token and then, if the bearer token was not
provided, the HTTP signature.
// Authorize authorizes the request first checking the required bearer token and then if the bearer token was not // provided the HTTP signature .
func (h *AuthHandler) Authorize(req *http.Request) (bool, *url.URL, error) {
	if h.tokenVerifier.Verify(req) {
		logger.Debugf("[%s] Authorization succeeded using bearer token for request %s", h.endpoint, req.URL)
		return true, h.ObjectIRI, nil
	}
	logger.Debugf("[%s] Authorization failed using bearer token for request %s.", h.endpoint, req.URL)
	if h.verifier == nil {
		return false, nil, nil
	}
	logger.Debugf("[%s] Checking HTTP signature for request %s...", h.endpoint, req.URL)
	ok, actorIRI, err := h.verifier.VerifyRequest(req)
	if err != nil {
		return false, nil, fmt.Errorf("verify HTTP signature: %w", err)
	}
	if !ok {
		logger.Debugf("[%s] Authorization failed using HTTP signature for request %s.", h.endpoint, req.URL)
		return false, nil, nil
	}
	ok, err = h.authorizeActor(actorIRI)
	if err != nil {
		return false, nil, fmt.Errorf("authorize actor [%s]: %w", actorIRI, err)
	}
	logger.Debugf("[%s] Authorization succeeded using HTTP signature for request %s.", h.endpoint, req.URL)
	return ok, actorIRI, nil
}
func ( h * AuthHandler ) Authorize ( req * http . Request ) ( bool , * url . URL , error ) { if h . tokenVerifier . Verify ( req ) { logger . Debugf ( " " , h . endpoint , req . URL ) return true , h . ObjectIRI , nil } logger . Debugf ( " " , h . endpoint , req . URL ) if h . verifier == nil { return false , nil , nil } logger . Debugf ( " " , h . endpoint , req . URL ) ok , actorIRI , err := h . verifier . VerifyRequest ( req ) if err != nil { return false , nil , fmt . Errorf ( " " , err ) } if ! ok { logger . Debugf ( " " , h . endpoint , req . URL ) return false , nil , nil } ok , err = h . authorizeActor ( actorIRI ) if err != nil { return false , nil , fmt . Errorf ( " " , actorIRI , err ) } logger . Debugf ( " " , h . endpoint , req . URL ) return ok , actorIRI , nil }
Authorize authorizes the request, first checking the required bearer token and then, if the bearer token was not
provided, the HTTP signature.
Authorize authorizes the request first checking the required bearer token and then if the bearer token was not provided the HTTP signature .
// The bearer of the token is assumed to be this service. If it isn't then validation // should fail in subsequent checks. // Check HTTP signature.