Skip to content

Feature/allow ominiauth_success json override #914

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,24 @@ mount_devise_token_auth_for 'User', at: 'auth', controllers: {
}
~~~

## Overriding the Omniauth Success resource serializer

Rendering an Omniauth success works a litte differently to the other controllers which is why there is no render override. Instead we provide a method to override how you want the resource (usually the user object) to be serialized. The default is:

~~~ruby
def serialize_omniauth_success_resource(resource)
resource.as_json
end
~~~

But you may not want to use the built in `as_json`. In which case, you can override it like this, for example:

~~~ruby
def serialize_omniauth_success_resource(resource)
MyCustomSerializer.new(resource).return_a_hash
end
~~~

**Note:** Controller overrides must implement the expected actions of the controllers that they replace.

## Passing blocks to Controllers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def omniauth_success

yield @resource if block_given?

render_data_or_redirect('deliverCredentials', @auth_params.as_json, @resource.as_json)
render_data_or_redirect('deliverCredentials', @auth_params.as_json, serialize_omniauth_success_resource(@resource))
end

def omniauth_failure
Expand All @@ -52,6 +52,11 @@ def omniauth_failure

protected

#override this method to provide your own serialization strategy
def serialize_omniauth_success_resource(resource)
resource.as_json
end

# this will be determined differently depending on the action that calls
# it. redirect_callbacks is called upon returning from successful omniauth
# authentication, and the target params live in an omniauth-specific
Expand Down