-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
366 additions
and
67 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Api::V1::Auth::SessionsController < ApplicationController | ||
before_action :authenticate_api_v1_user! | ||
|
||
def index | ||
if current_api_v1_user | ||
render json: { is_login: true, data: current_api_v1_user } | ||
else | ||
render json: { is_login: false, message: "ユーザーが存在しません" } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
class ApplicationController < ActionController::API | ||
end | ||
include DeviseTokenAuth::Concerns::SetUserByToken | ||
before_action :skip_session | ||
protected | ||
def skip_session | ||
request.session_options[:skip] = true | ||
end | ||
end |
61 changes: 61 additions & 0 deletions
61
app/controllers/concerns/overrides/omniauth_callbacks_controller.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 @@ | ||
module Overrides | ||
|
||
class OmniauthCallbacksController < DeviseTokenAuth::OmniauthCallbacksController | ||
skip_before_action :skip_session | ||
|
||
def redirect_callbacks | ||
super | ||
end | ||
|
||
def omniauth_success | ||
super | ||
update_auth_header | ||
end | ||
|
||
def omniauth_failure | ||
super | ||
end | ||
|
||
protected | ||
def assign_provider_attrs(user, auth_hash) | ||
case auth_hash['provider'] | ||
when 'twitter' | ||
user.assign_attributes({ | ||
nickname: auth_hash['info']['nickname'], | ||
name: auth_hash['info']['name'], | ||
image: auth_hash['info']['image'], | ||
email: auth_hash['info']['email'] | ||
}) | ||
else | ||
super | ||
end | ||
end | ||
|
||
def get_resource_from_auth_hash | ||
super | ||
# @resource.credentials = auth_hash["credentials"] | ||
clean_resource | ||
end | ||
|
||
def render_data_or_redirect(message, data, user_data = {}) | ||
if ['inAppBrowser', 'newWindow'].include?(omniauth_window_type) | ||
render_data(message, user_data.merge(data)) | ||
elsif auth_origin_url | ||
redirect_to DeviseTokenAuth::Url.generate(auth_origin_url, data.merge(blank: true)) | ||
else | ||
fallback_render data[:error] || 'An error occurred' | ||
end | ||
end | ||
|
||
def clean_resource | ||
if auth_hash['provider'] == 'twitter' | ||
@resource.name = strip_emoji(@resource.name) | ||
@resource.nickname = strip_emoji(@resource.nickname) | ||
end | ||
end | ||
def strip_emoji(str) | ||
str.encode('SJIS', 'UTF-8', invalid: :replace, undef: :replace, replace: '').encode('UTF-8') | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
class User < ActiveRecord::Base | ||
extend Devise::Models | ||
# Include default devise modules. Others available are: | ||
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable | ||
devise :database_authenticatable, :registerable, | ||
:recoverable, :rememberable, :validatable, :omniauthable | ||
include DeviseTokenAuth::Concerns::User | ||
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.