[CB-4.3] cbauth module implementation

Hi all,

Thanks again for your help on a previous issue.

I’m going to try to implement the cbauth forgebox module for my authentication, but I’m confused by this statement in his readme:

Specify a userServiceClass in your config/ColdBox.cfc inside moduleSettings.cbauth.userServiceClass. This component needs to have three methods:

  1. isValidCredentials( username, password )
  2. retrieveUserByUsername( username )
  3. retrieveUserById( id )

It reads like, “specify something to do with userServiceClass in your config/coldbox.cfc which is inside moduleSettings.cbauth.userServiceClass.” Since the moduleSettings.cbauth.userServiceClass isn't actually a file path in my app (at least not using Commandbox to install the module...), it's unclear to me what exactly the author means. Have any of you used this module? If so, how did you go about registering it as a dependency?

Many thanks,

Hi Roy,

Glad to hear it’s going well. I haven’t used that particular module before. I typically use cbsecurity (https://www.forgebox.io//view/cbsecurity ), with a custom rules and validator model. You can see an example of the implementation in the ContentBox module configuration here:

https://github.com/Ortus-Solutions/ContentBox/blob/5f3cef1f4864ef5167106c27cb57e507d298fb69/modules/contentbox/modules/contentbox-admin/modules/contentbox-security/ModuleConfig.cfc#L60

It sounds like it accomplishes pretty much the same thing that cbauth does.

HTH,

Jon

Excellent, thanks for the recommendation. It has more straightforward documentation so I’ll try that out in the AM.

Many thanks,

Any thoughts on why I’m throwing this error? Sorry for being needy with this stuff…

`

Builder.BuildCFCDependencyException

Error building: cbsecurity.interceptors.Security -> The parameter controller to function init is required but was not passed in.
`

I’m requesting the dependency in handlers/Login.cfc:

`

property name=“CBSecurity” inject=“cbsecurity.interceptors.Security”;

`

I’m not sure what you’re after, but I don’t think you should be directly injecting an interceptor into a handler? What method in the interceptor are you planning on calling and why?

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

I was picturing handlers as controllers in other frameworks, so I was calling CBSecurity as a depency into the handler in order to hopefully call the method _isUserInValidState, but I’m realizing this is a private method anyway so probably not accessible.

I suppose I’ll need to look into the docs more on how to implement this.

Handlers, are controllers, but I think you may be confused about what interceptors are, or at least putting methods in them that don’t really belong. It sounds like your method you wish to call should be in a service. Interceptors should only be registered as an interceptor in the Coldbox config and the framework will automatically call its methods based on the events they are listening to.

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Yeah I think you’re right, my understanding of interceptors is incorrect. Will read up over the weekend.

Many thanks!

Keep in mind that it’s perfectly acceptable (and even desired) to put all your “real” business logic in a service and then simply inject that service into the interceptor to use. Then you can re-use the service calls elsewhere in your application, which simply leaves your interceptor as a listener for the framework events and proxying the logic over to the service.

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Ah, ok. That makes more sense.

Thanks!