Kebin Maharjan - 375 - Nov 25, 2014

Hi Demis,
How do I resolve RegistrationService  with custom user type from controller? I tried the following: 
ResolveService<RegisterService<MyUserType>>()
This is returning null.

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

Thanks,
Kebin

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:
https://github.com/ServiceStack/ServiceStack/blob/master/src/ServiceStack/Auth/RegisterService.cs#L49

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

[DefaultRequest(typeof(Register))]
public class CustomRegisterService : RegisterService<MyUserAuth> { }

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

appHost.RegisterService<CustomRegisterService>("/register");
appHost.RegisterAs<RegistrationValidator, IValidator<Register>>();

Which is basically all the RegistrationFeature does: 
https://github.com/ServiceStack/ServiceStack/blob/master/src/ServiceStack/RegistrationFeature.cs

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).

Thanks!

Look at Session or Auth Events: https://github.com/ServiceStack/ServiceStack/wiki/Sessions#session-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?

Thanks!

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: https://github.com/ServiceStack/ServiceStack/commit/f2383fffd390d58d2da55dd47eb2b68110066c51

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: https://github.com/ServiceStack/ServiceStack/wiki/MyGet

Kebin Maharjan:

Works great! Thanks :slight_smile: