Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sign up automatically after registration #955

Closed
OndrejPontes opened this issue Apr 25, 2017 · 5 comments
Closed

Sign up automatically after registration #955

OndrejPontes opened this issue Apr 25, 2017 · 5 comments

Comments

@OndrejPontes
Copy link

I have read a lot of tutorials and discussions about a doorkeeper and many people try to solve how to sign up automatically after registration, but nobody mentioned how to do that.

Is something like that possible to configure in doorkeeper and if so, how to do it ?

@thijsnado
Copy link

thijsnado commented May 30, 2017

@OndrejPontes I'd assume it's the same as normal login, in that you re-direct to same oauth endpoint:

  # in config/doorkeeper
  resource_owner_authenticator do
    user = # the_code_that_finds_user, varies from app to app, warden.user works if you do devise
    if user
      user
    else
      redirect_to(login_or_register_path(after_login_path: request.full_path)
    end
  end

  # in login controller
  def login
    user = the_code_to_login_user # varies from app to app

    if user
      login(user)
      if params[:after_login_path] # this you need to make sure to pass from links to initial redirect path
        redirect_to(params[:after_login_path]
      end
    else
      # handle bad username and password
    end
  end

  # in register user controller
  def create
    user = User.new(permitted_user_params)
    if user.save
      login(user)
      if params[:after_login_path] # this you need to make sure to pass from links to initial redirect path
        redirect_to(params[:after_login_path]
      end
    else
      # handle invalid user
    end
  end

Obviously above example could use some refactoring but general gist is you try to pass the original url to place you authenticate user (wether through login or though registration) and then redirect back at end.

@nbulaj
Copy link
Member

nbulaj commented Feb 2, 2018

Hi @OndrejPontes. Does @moger777 solution solves your problem?

@OndrejPontes
Copy link
Author

OndrejPontes commented Feb 2, 2018 via email

@nbulaj
Copy link
Member

nbulaj commented Feb 2, 2018

Ok, so currently I'm closing this issue (because there is no bug), but remind myself to add a new Wiki page :)

UPD: ready

@nbulaj nbulaj closed this as completed Feb 2, 2018
@OndrejPontes
Copy link
Author

OndrejPontes commented Feb 2, 2018 via email

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

No branches or pull requests

3 participants