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

Unable to override create method to handle user creation validation error. #144

Open
lethunder opened this issue Jul 16, 2019 · 7 comments

Comments

@lethunder
Copy link

Hello,
It there a way to override create method to handle validation error during user creattiln process?

Thanks in advance

@adamstegman
Copy link
Collaborator

adamstegman commented Jul 16, 2019

Yes, you can set devise.saml_update_resource_hook to a proc. Use the default as a starting point and you can customize from there!

@lethunder
Copy link
Author

lethunder commented Jul 16, 2019 via email

@lethunder
Copy link
Author

lethunder commented Jul 17, 2019 via email

@adamstegman
Copy link
Collaborator

Redirection can be tricky, depending on when you want to do it!

The basic flow is something like:

So that flow goes through this gem, devise, and warden at various points—if you raise an error, you might be able to catch it in the controller, in #create, but I'm not sure.

Another place you could catch it is in the FailureApp#redirect_url - this is called by warden when an unauthorized response is occurring. We use this in our app to display an error page when the wrong scope is in use.

@lethunder
Copy link
Author

lethunder commented Jul 18, 2019 via email

@luke-zhou
Copy link
Contributor

luke-zhou commented Aug 5, 2020

I am currently having the same issue.

      if resource.nil?
        if Devise.saml_create_user
          logger.info("Creating user(#{auth_value}).")
          resource = new
        else
          logger.info("User(#{auth_value}) not found.  Not configured to create the user.")
          return nil
        end
      end
      if Devise.saml_update_user || (resource.new_record? && Devise.saml_create_user)
        Devise.saml_update_resource_hook.call(resource, decorated_response, auth_value)
      end
      resource

`
I think in the model.rb, if creating fails should return nil in the resource instead of an empty resource. In that case, the strategy can fail the authentication

@adamstegman
Copy link
Collaborator

Great catch! That does sound like the right response.

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

No branches or pull requests

3 participants