-
Notifications
You must be signed in to change notification settings - Fork 4
Conversation
e3b5ad2
to
4cb7f0e
Compare
@takashi @yujinakayama レビューお願いします 🙏 |
@takashi の助言でCookieStoreにAuthHash保存するようにした。 |
そういえば、メール認証をしないとログインできないので新規登録までに、
…と使えるようになるまでに2回Qiitaで参加ボタンを押す必要があるのが面倒だ… |
app/models/oauth_authorization.rb
Outdated
@@ -0,0 +1,3 @@ | |||
class OauthAuthorization < ApplicationRecord |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OauthAuthorization という名前、 Authorization と2回行っているようで不自然なのと、 Oauth(という仕様)とのAuthorization のようにとれ、違和感があります。
この場合 Qiita との Authorization なわけなので、QiitaAuthorization とするのはどうでしょうか
User.new( | ||
email: email, | ||
locale: locale, | ||
password: password, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここで password をユーザの代わりに追加しているけど、このパスワードはユーザーに知らされる?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
知らされないので、パスワードを再発行するまでパスワード認証は実質利用できない状態です。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private | ||
|
||
def store_omniauth_auth | ||
session[:devise_omniauth_auth] = request.env['omniauth.auth'].to_json, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cookie store を使用しているならば、serializer を marshal
にしていても json
にしていても hash はそのまま格納できるはずです。 to_json 必要なさそう
0057a13
to
b7aee85
Compare
@takashi 再度レビューお願いします |
@@ -0,0 +1,34 @@ | |||
# frozen_string_literal: true | |||
|
|||
class Auth::OmniauthCallbacksController < Devise::OmniauthCallbacksController |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
今更なのですが、 ここで行っているのは結局 QiitaAuthorization モデルの作成ですし、Setting の方も QiitaAuthorizationsController なのでAuth::QiitaAuthorizationsController
が適当なのではないかと思います 🙇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QiitaAuthorizationsを確かに作成してはいるのですが、どちらかと言うとここはDeviseの提供する仕組みの上でOmniauthのcallbackを処理する性格のほうが強いので、Deviseの命名に寄せていた方が良いと考えているのですが、どう思いますか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Omniauthのcallbackを処理するが、実際には Oauth Server 側 (今回だとQiita) で明示的にResource Owner のリソースを OauthClient 受け渡すための callback url を記述しているので、omniauth という gem が提供している仕組みではあるが QiitaAuthorization を作成する、という考え方がしっくりくるのかな、と思った。
けど特に強い意見があるわけではないのでこのままでも大丈夫です 🙆♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
補足すると、 qiita
というアクションに違和感があって、 アクションは原則 crud のみで構成されるべき、という rails の controller の実装的にこうすればいいんじゃないか、とおもった、というのもあります (Qiita:Authorization#create でもいいのではという意味)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
qiita というアクションに違和感があって、 アクションは原則 crud のみで構成されるべき、という rails の controller の実装的にこうすればいいんじゃないか
これはたしかにそうだと思いますが、今回は素直に提供する仕組みに乗っかって様子見ようと思います。forkなので。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
なるほど、本家がそういう実装なのか。 okです 👌
} | ||
|
||
AlertBar.propTypes = { | ||
isEmailConfirmed: PropTypes.bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これは require 属性をつけなくても大丈夫ですか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
付けといたほうが良さそうですね、thx 🙇
{ | ||
(!isEmailConfirmed && | ||
<div className='alert'> | ||
<i className='fa fa-fw fa-exclamation-triangle' /><FormattedMessage id='alert_bar.email_confirm_alert' defaultMessage='Your email address is not confirmed. Please confirm the sent email.' /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defaultMessage
が使われるのはどのようなケースですか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else | ||
flash[:alert] = I18n.t('omniauth_callbacks.failure') | ||
end | ||
redirect_to settings_qiita_authorizations_path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
インデントが1つ深いかも
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😳
def qiita | ||
auth_hash = request.env['omniauth.auth'] | ||
|
||
if current_user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この 「current_user が存在した場合」というのは 既存の password 認証のアカウントに Qiita アカウントに紐付ける というプロセスなので、今すぐには必要ない部分ですか?(消す必要はないと思っているが確認です)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
はい、現状使われることはない部分です 🙆
@takashi 修正 or コメントしたので再度レビューお願いします 🙏 |
@@ -14,6 +14,7 @@ const ja = { | |||
"account.unblock": "ブロック解除", | |||
"account.unfollow": "フォロー解除", | |||
"account.unmute": "ミュート解除", | |||
"alert_bar.email_confirm_alert": "メールアドレスの確認が完了していません。登録したアドレス宛に送信されたメールを確認してください。", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1日の期限をもってログインできなくなるよ、という旨をここで書いたほうが親切かなと思ったけどどうでしょう?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
確かにそうですね👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@takashi レビューthx 🙏 |
Conflicts: Gemfile Gemfile.lock app/javascript/mastodon/features/compose/index.js app/serializers/initial_state_serializer.rb app/views/about/_registration.html.haml app/views/admin/settings/edit.html.haml app/views/auth/registrations/edit.html.haml app/views/shared/_og.html.haml config/initializers/omniauth.rb package.json Look at f6df9d0 . The diff is too difficult to read however, in file app/views/auth/registrations/edit.html.haml, `simple_form.labels.defaults.password` was suddenly replaced to `simple_form.labels.defaults.new_password`. This can be proved by this file on ef27a0b which is a parent commit of that. However, this replacement has been continued for about 3 years. And there is no significant difference. So, I decided not to recover this replacement. ref: - 1cd0497 - increments#8 - f4d549d - mastodon#8703
QiitaのOAuthを利用してアカウント作成とログインが行えるようにする。
仕様
/about
)とログイン画面 (/session/new
) に「Qiitaアカウントで参加ボタン」が追加される- ユーザーには知らされないので再設定するまでパスワードログインできない
- 設定画面からパスワードを設定することが出来る。最初の1回だけ現在のパスワードを入れずにパスワードを変更することが出来る
動作を見たい場合の注意
QIitaで自分のアカウントでアプリケーションを作成し、
.env
に適宜以下の内容を追加しておいてください。