-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #175 from graphql-devise/allow-controller-level-au…
…thentication Allow controller level authentication
- Loading branch information
Showing
22 changed files
with
213 additions
and
109 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
app/controllers/graphql_devise/concerns/additional_controller_methods.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# frozen_string_literal: true | ||
|
||
module GraphqlDevise | ||
module Concerns | ||
module AdditionalControllerMethods | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
attr_accessor :client_id, :token, :resource | ||
end | ||
|
||
def gql_devise_context(models) | ||
{ | ||
current_resource: authenticate_model(models), | ||
controller: self | ||
} | ||
end | ||
|
||
def authenticate_model(models) | ||
Array(models).each do |model| | ||
set_resource_by_token(model) | ||
return @resource if @resource.present? | ||
end | ||
|
||
nil | ||
end | ||
|
||
def resource_class(resource = nil) | ||
# Return the resource class instead of looking for a Devise mapping if resource is already a resource class | ||
return resource if resource.respond_to?(:find_by) | ||
|
||
super | ||
end | ||
|
||
def full_url_without_params | ||
request.base_url + request.path | ||
end | ||
|
||
def set_resource_by_token(resource) | ||
set_user_by_token(resource) | ||
end | ||
|
||
def graphql_context(resource_name) | ||
{ | ||
resource_name: resource_name, | ||
controller: self | ||
} | ||
end | ||
|
||
def build_redirect_headers(access_token, client, redirect_header_options = {}) | ||
{ | ||
DeviseTokenAuth.headers_names[:"access-token"] => access_token, | ||
DeviseTokenAuth.headers_names[:client] => client, | ||
:config => params[:config], | ||
:client_id => client, | ||
:token => access_token | ||
}.merge(redirect_header_options) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
app/models/graphql_devise/concerns/additional_model_methods.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'graphql_devise/model/with_email_updater' | ||
|
||
module GraphqlDevise | ||
module Concerns | ||
module AdditionalModelMethods | ||
extend ActiveSupport::Concern | ||
|
||
class_methods do | ||
def reconfirmable | ||
devise_modules.include?(:confirmable) && column_names.include?('unconfirmed_email') | ||
end | ||
end | ||
|
||
def update_with_email(attributes = {}) | ||
GraphqlDevise::Model::WithEmailUpdater.new(self, attributes).call | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.