Kebin Maharjan - 375 - Nov 25, 2014

Hi Demis,
How do I resolve RegistrationService  with custom user type from controller? I tried the following: 
This is returning null.

If I resolve with ResolveService<RegisterService>(), registration creates documents of type UserAuth instead of my custom type.


You can only resolve a Service or Dependency that has been registered (IOTW you can’t resolve something that doesn’t exist).

As you’ve noticed the RegisterService looks at the default UserAuth:

So you wont be able to use the existing RegisterService, instead you’ll need to create your own custom RegisterService, e.g:

public class CustomRegisterService : RegisterService<MyUserAuth> { }

And register to use your own Service instead of using the built-in RegistrationFeature with:

appHost.RegisterAs<RegistrationValidator, IValidator<Register>>();

Which is basically all the RegistrationFeature does:

Kebin Maharjan:

Ah I see! Thanks!

Is there a hook like OnRegistered for OAuth providers? For example, sending out an email after registering using Facebook. OAuth callbacks hits ForwardingController, but this gets called all the time (whenever user authenticates with the service).


Look at Session or Auth Events:

Kebin Maharjan:

Hi Demis,
It doesn’t look like OnRegistered is being called when creating account using OAuth provider(Facebook).  I followed the example for both Session events and Auth Events. OnLogOut, OnAuthenticated works fine but not the OnRegistered. Any ideas?


OnRegistered only gets called when user is explicitly registered using the /register service. Only OnAuthenticated() gets called for AuthProviders. Currently you’ll need to load the userAuth from the authRepo in OnAuthenticated() and check that u.CreatedDate == u.ModifiedDate to see if it was just created (i.e Registered) or they’re signing in again.

I’ll look at adding support for OnRegistered for OAuthProviders, but it’s going to require a breaking interface change.

Kebin Maharjan:

I see. Thanks for the quick response! If it is a breaking change, it probably won’t be added anytime sooner?

It’s breaking if you’re implementing your own IAuthRepository otherwise if you’re using existing ones you shouldn’t be affected. Either way I’ve just added support for it in this commit:

It’s just finished going through CI and is now deploying to MyGet, will be available in 10-15 mins, will let you know when it’s finished deploying

ok just finished deploying, you can get it from:

Kebin Maharjan:

Works great! Thanks :slight_smile: