clojure: No implementation of method of protocol found for class

duplic8

I have a ring server. I am using Buddy for authentication / authorization. I implemented my own token backend by implementing -parse, -authenticate, and -handle-unauthorized of the buddy protocols IAuthentication and IAuthorization. Here it is:

(ns myproject.auth
  (:require [buddy.auth.protocols :as proto]))

...

(defn my-token-backend
  ([] (my-token-backend nil))
  ([{:keys [unauthorized-handler]}]
   (reify
     proto/IAuthentication
     (-parse [_ request]
       (token-or-nil))
     (-authenticate [_ request token]
       (get-user-from-token token))
     proto/IAuthorization
     (-handle-unauthorized [_ request metadata]
       (if unauthorized-handler
         (unauthorized-handler request metadata)
         (handle-unauthorized-default request))))))

I then use my backend in wrap-authentication and wrap-authorization middleware:

(defn middleware [handler]
  (-> handler
      (wrap-authentication my-token-backend)
      (wrap-authorization my-token-backend)

...and call my app with that middleware like so: (def app (middleware main-routes)).

When I go to my index page in my browser, I get the following error: java.lang.IllegalArgumentException: No implementation of method: :-parse of protocol: #'buddy.auth.protocols/IAuthentication found for class: myproject.auth$my_token_backend.

When I call (reflect my-token-backend) in the REPL, I noticed the dashes in the names of the methods -parse, -authenticate, and -handle-unauthorized have been converted to underscores. Is this why I'm getting that error, or is the error coming from somewhere else?


Edit: After Sean's comment, I've changed my middleware to look like the following:

(defn middleware [handler]
  (-> handler
      (wrap-authentication (my-token-backend))
      (wrap-authorization (my-token-backend))))
Sean Corfield

The class myproject.auth$my_token_backend is the function my-token-backend and the error you are getting says that the call to -parse is expecting an object that implements the protocols -- which would be the result of calling your function.

So I think you want:

(defn middleware [handler]
  (-> handler
      (wrap-authentication (my-token-backend))
      (wrap-authorization (my-token-backend)))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Clojure: No implementation of method in protocol

No implementation of method: :take! of protocol: #'clojure.core.async.impl.protocols/ReadPort found for class: clojure.core.async$chan

IllegalArgumentException: No implementation of method: :as-file of protocol: #'clojure.java.io/Coercions found for class: clojure.lang.Symbol

No implementation of method: :as-file of protocol: #'clojure.java.io/Coercions found for class: java.lang.Character in leiningen project file

Clojure - No matching method found

Clojure - how to instrument another protocol in implementation

Protocol for class method

Proper implementation of Sequence Protocol in a Class

No matching method found with JDBI and Clojure

Always the default implementation of protocol gets called even after implementing the method in class extension in an XCTest file

Gradle DSL method not found: 'implementation()'

Is there a way to know that method is protocol implementation in Swift?

Swift protocol with generic method: invalid redeclaration of implementation

Calling protocol default implementation from regular method

Protocol implementation on a class with @MainActor - how to avoid warnings?

Game State Implementation Using Protocol And Base Class

Class method "+sharedDelegate" not found

Codeigniter method not found in class

swift protocol extension default implementation vs actual implementation in class

method in protocol extension gets called instead of method implementation in View Controller

Factory method for a generic implementation class

Optional method implementation in an abstract class

Application specific implementation of a class method

Flutter: android MissingPluginException(No implementation found for method getApplicationDocumentsDirectory)

MissingPluginException No implementation found for method copyText on channel iOS

'Self' is only available in a protocol or as the result of a class method

Swift protocol defining class method returning self

Custom method on class that conforms to MKAnnotation protocol

Method 'QueryBuilder' not found in class ObjectRepository