code: func (tam *TokenAuthorizationMiddleware) BearerRequestIsAuthorized(ctx context.Context, r *http.Request) (bool, error) {
  	token := tam.TokenFromBearerRequest(ctx, r)
  	xptid := r.Header.Get("X-PacketFence-Tenant-Id")
  
  	tokenInfo, _ := tam.tokenBackend.TokenInfoForToken(token)
  
  	if tokenInfo == nil {
  		return false, errors.New("Invalid token info")
  	}
  
  	var tenantId int
  
  	if tokenInfo.TenantId == AccessAllTenants && xptid == "" {
  		log.LoggerWContext(ctx).Debug("Token wasn't issued for a particular tenant and no X-PacketFence-Tenant-Id was provided. Request will use the default PacketFence tenant")
  	} else if xptid == "" {
  		log.LoggerWContext(ctx).Debug("Empty X-PacketFence-Tenant-Id, defaulting to token tenant ID")
  		tenantId = tokenInfo.TenantId
  		r.Header.Set("X-PacketFence-Tenant-Id", strconv.Itoa(tenantId))
  	} else {
  		var err error
  		tenantId, err = strconv.Atoi(xptid)
  		if err != nil {
  			msg := fmt.Sprintf("Impossible to parse X-PacketFence-Tenant-Id %s into a valid number, error: %s", xptid, err)
  			log.LoggerWContext(ctx).Warn(msg)
  			return false, errors.New(msg)
  		}
  	}
  
  	roles := make([]string, len(tokenInfo.AdminRoles))
  	i := 0
  	for r, _ := range tokenInfo.AdminRoles {
  		roles[i] = r
  		i++
  	}
  	r.Header.Set("X-PacketFence-Admin-Roles", strings.Join(roles, ","))
  
  	r.Header.Set("X-PacketFence-Username", tokenInfo.Username)
  
  	return tam.IsAuthorized(ctx, r.Method, r.URL.Path, tenantId, tokenInfo)
  }
docs: // Checks whether or not that request is authorized based on the path and method
  // It will extract the token out of the Authorization header and call the appropriate method