Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Parameters are not accessible from within keyauth #93

Closed
DavZim opened this issue Dec 23, 2022 · 4 comments
Closed

Parameters are not accessible from within keyauth #93

DavZim opened this issue Dec 23, 2022 · 4 comments
Labels
🤔 Question Further information is requested

Comments

@DavZim
Copy link
Contributor

DavZim commented Dec 23, 2022

While preparing the tests for #90 , I found that the c.AllParams() or c.Params(param) do not return any values from within keyauth.

To replicate this issue, consider this example

package main

import (
  "fmt"

  "github.com/gofiber/fiber/v2"
  "github.com/gofiber/keyauth/v2"
)

var (
  APIKey = "password1"
)

func main() {
  app := fiber.New()

  app.Use(keyauth.New(keyauth.Config{
    KeyLookup:  "param:access_token",
    Validator:  func(c *fiber.Ctx, key string) (bool, error) {
      if key == APIKey {
        return true, nil
      }
      return false, keyauth.ErrMissingOrMalformedAPIKey
    },
  }))

  app.Get("/:access_token", func(c *fiber.Ctx) error {
    return c.SendString(fmt.Sprintf("Found Parameters: %+v\n", c.AllParams()))
  })

  app.Listen(":3000")
}

When accessing the app with curl http://localhost:3000/password1 it returns 200 - missing or malformed API Key (not expected as the access_token is given the correct key).

When I remove the keyauth part and query the API again with the above command, I receive Found Parameters: map[access_token:password1] (expected).

While debugging this, I injected the following print statement in func keyFromParam

fmt.Printf("Found Parameters: '%v'", c.AllParams())

and for the above request, it printed: Found Parameters: 'map[]', meaning there is no key found when extracting the password, hence this issue.

@ReneWerner87
Copy link
Member

This is the normal expected behavior, the keyauth middleware runs on a route without parameters "/"

@DavZim
Copy link
Contributor Author

DavZim commented Dec 23, 2022

How would I then specify and access the param values for authentication?

@ReneWerner87 ReneWerner87 added the 🤔 Question Further information is requested label Dec 23, 2022
@ReneWerner87
Copy link
Member

ReneWerner87 commented Dec 23, 2022

app.Use("/:accessToken", keyauthMiddleware)

@DavZim
Copy link
Contributor Author

DavZim commented Dec 23, 2022

Got it. I created test cases for this in #90

@DavZim DavZim closed this as completed Dec 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🤔 Question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants