Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

sign_in method for backend sign in #46

Closed
nicolasiensen opened this issue May 22, 2014 · 3 comments
Closed

sign_in method for backend sign in #46

nicolasiensen opened this issue May 22, 2014 · 3 comments

Comments

@nicolasiensen
Copy link

I want to sign in users with Casino after they successfully submit the sign up form.

Something like the Devise's sign_in method.

Thoughts?

@luxflux
Copy link
Member

luxflux commented May 25, 2014

As CASino does not support user creation (sign up), only login (sign in), I assume you want to do this in another app. You can use the API to sign the new user in, check #38 and #40 for an example.

@luxflux luxflux closed this as completed May 25, 2014
@nicolasiensen
Copy link
Author

I'm reusing LoginCredentialAcceptor to auto login users. In my case users are signing up with Devise, after sign up they are redirected to an action I built in UsersController#sign_in.

This action receives username and password as get parameters , and deal with LoginCredentialAcceptor to login the signed up user.

I also had to include CASino::ProcessorConcern::LoginTickets in the top of the controller.

This was referenced May 25, 2014
@nozpheratu
Copy link

For future visitors, here's a more up-to-date example using the ActiveRecord authenticator:

class RegistrationsController < Devise::RegistrationsController
  include CASino::SessionsHelper

  private

  def sign_up(resource_name, resource)
    return unless params.has_key?(:service)
    data = { authenticator: 'ActiveRecord', user_data: { username: resource.email }}
    sign_in(data)
  end

  # Prevents render/redirect conflicts between Devise & CASino, also makes the
  # service_with_ticket_url available for Devise to follow after registration.
  def handle_signed_in_with_service(tgt, options)
    if !service_allowed?(params[:service])
      @service = params[:service]
      render 'casino/sessions/service_not_allowed', status: 403
    else
      @url = acquire_service_ticket(tgt, params[:service], options).service_with_ticket_url
    end
  end

  def after_sign_up_path_for(resource)
    params.has_key?(:service) ? @url : super
  end
end

In order for this to work you'll need to ensure the service param is forwarded through the registration pipeline (e.g., registration link on the login page and the following registration form tag). I'm sure this example can be improved but it should give you a decent starting point.

Edit: Make sure you're only passing params[:service] and and not the entire params hash in your devise links/form tags. Otherwise you'll break devise as your params hash content will override anything you enter into the forms.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants