func (a *APIKeyAuth) Authenticate(req *http.Request, route string) (middleware.AuthStatus, context.Context, error) {
	var haddr *hash.Hash = nil
	if !a.AdminKeys {
		// Check if the address actually exists
		var err error
		haddr, err = hash.NewFromHash(mux.Vars(req)["addr"])
		if err != nil {
			logrus.Trace("auth: addr not found in url")
			return middleware.AuthStatusPass, nil, nil
		}

		accountRepo := container.Instance.GetAccountRepo()
		if !accountRepo.Exists(*haddr) {
			logrus.Trace("auth: address not found")
			return middleware.AuthStatusPass, nil, nil
		}
	}

	// Check api key.
	k, err := a.checkAPIKey(req.Header.Get("Authorization"), haddr, route)
	if err != nil {
		logrus.Trace("auth: checkApiKey failed: ", err)
		return middleware.AuthStatusPass, nil, nil
	}

	ctx := req.Context()
	ctx = context.WithValue(ctx, middleware.APIKeyContext, k)

	logrus.Trace("auth: checkApiKey success: ", err)
	return middleware.AuthStatusSuccess, ctx, nil
}
// Authenticate will check if an API key matches the request
Authenticate will check if an API key matches the request
// Authenticate will check if an API key matches the request
func (a *APIKeyAuth) Authenticate(req *http.Request, route string) (middleware.AuthStatus, context.Context, error) {
	var haddr *hash.Hash = nil
	if !a.AdminKeys {
		var err error
		haddr, err = hash.NewFromHash(mux.Vars(req)["addr"])
		if err != nil {
			logrus.Trace("auth: addr not found in url")
			return middleware.AuthStatusPass, nil, nil
		}
		accountRepo := container.Instance.GetAccountRepo()
		if !accountRepo.Exists(*haddr) {
			logrus.Trace("auth: address not found")
			return middleware.AuthStatusPass, nil, nil
		}
	}
	k, err := a.checkAPIKey(req.Header.Get("Authorization"), haddr, route)
	if err != nil {
		logrus.Trace("auth: checkApiKey failed: ", err)
		return middleware.AuthStatusPass, nil, nil
	}
	ctx := req.Context()
	ctx = context.WithValue(ctx, middleware.APIKeyContext, k)
	logrus.Trace("auth: checkApiKey success: ", err)
	return middleware.AuthStatusSuccess, ctx, nil
}
func ( a * APIKeyAuth ) Authenticate ( req * http . Request , route string ) ( middleware . AuthStatus , context . Context , error ) { var haddr * hash . Hash = nil if ! a . AdminKeys { var err error haddr , err = hash . NewFromHash ( mux . Vars ( req ) [ " " ] ) if err != nil { logrus . Trace ( " " ) return middleware . AuthStatusPass , nil , nil } accountRepo := container . Instance . GetAccountRepo ( ) if ! accountRepo . Exists ( * haddr ) { logrus . Trace ( " " ) return middleware . AuthStatusPass , nil , nil } } k , err := a . checkAPIKey ( req . Header . Get ( " " ) , haddr , route ) if err != nil { logrus . Trace ( " " , err ) return middleware . AuthStatusPass , nil , nil } ctx := req . Context ( ) ctx = context . WithValue ( ctx , middleware . APIKeyContext , k ) logrus . Trace ( " " , err ) return middleware . AuthStatusSuccess , ctx , nil }
Authenticate will check if an API key matches the request
Authenticate will check if an API key matches the request
// Check if the address actually exists // Check api key.