Added Instagram login method
This commit is contained in:
parent
15ce3b2f49
commit
5c603bf8ec
1
Gemfile
1
Gemfile
|
@ -78,6 +78,7 @@ gem 'omniauth-openid'
|
||||||
gem 'openid-redis-store'
|
gem 'openid-redis-store'
|
||||||
gem 'omniauth-facebook'
|
gem 'omniauth-facebook'
|
||||||
gem 'omniauth-twitter'
|
gem 'omniauth-twitter'
|
||||||
|
gem 'omniauth-instagram'
|
||||||
|
|
||||||
# forked while https://github.com/intridea/omniauth-github/pull/41 is being upstreamd
|
# forked while https://github.com/intridea/omniauth-github/pull/41 is being upstreamd
|
||||||
gem 'omniauth-github-discourse', require: 'omniauth-github'
|
gem 'omniauth-github-discourse', require: 'omniauth-github'
|
||||||
|
|
|
@ -37,6 +37,7 @@ Discourse.LoginMethod.reopenClass({
|
||||||
"cas",
|
"cas",
|
||||||
"twitter",
|
"twitter",
|
||||||
"yahoo",
|
"yahoo",
|
||||||
|
"instagram",
|
||||||
"github"
|
"github"
|
||||||
].forEach(function(name){
|
].forEach(function(name){
|
||||||
if (Discourse.SiteSettings["enable_" + name + "_logins"]) {
|
if (Discourse.SiteSettings["enable_" + name + "_logins"]) {
|
||||||
|
|
|
@ -129,6 +129,12 @@
|
||||||
content: $fa-var-google;
|
content: $fa-var-google;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
&.instagram {
|
||||||
|
background: $instagram;
|
||||||
|
&:before {
|
||||||
|
content: $fa-var-instagram;
|
||||||
|
}
|
||||||
|
}
|
||||||
&.facebook {
|
&.facebook {
|
||||||
background: $facebook;
|
background: $facebook;
|
||||||
&:before {
|
&:before {
|
||||||
|
|
|
@ -13,6 +13,7 @@ $large-width: 1110px !default;
|
||||||
// --------------------------------------------------
|
// --------------------------------------------------
|
||||||
|
|
||||||
$google: #5b76f7 !default;
|
$google: #5b76f7 !default;
|
||||||
|
$instagram: #125688 !default;
|
||||||
$facebook: #3b5998 !default;
|
$facebook: #3b5998 !default;
|
||||||
$cas: #70BA61 !default;
|
$cas: #70BA61 !default;
|
||||||
$twitter: #00bced !default;
|
$twitter: #00bced !default;
|
||||||
|
|
|
@ -10,7 +10,8 @@ class Users::OmniauthCallbacksController < ApplicationController
|
||||||
Auth::GoogleOAuth2Authenticator.new,
|
Auth::GoogleOAuth2Authenticator.new,
|
||||||
Auth::OpenIdAuthenticator.new("yahoo", "https://me.yahoo.com", trusted: true),
|
Auth::OpenIdAuthenticator.new("yahoo", "https://me.yahoo.com", trusted: true),
|
||||||
Auth::GithubAuthenticator.new,
|
Auth::GithubAuthenticator.new,
|
||||||
Auth::TwitterAuthenticator.new
|
Auth::TwitterAuthenticator.new,
|
||||||
|
Auth::InstagramAuthenticator.new
|
||||||
]
|
]
|
||||||
|
|
||||||
skip_before_filter :redirect_to_login_if_required
|
skip_before_filter :redirect_to_login_if_required
|
||||||
|
@ -18,7 +19,7 @@ class Users::OmniauthCallbacksController < ApplicationController
|
||||||
layout false
|
layout false
|
||||||
|
|
||||||
def self.types
|
def self.types
|
||||||
@types ||= Enum.new(:facebook, :twitter, :google, :yahoo, :github, :persona, :cas)
|
@types ||= Enum.new(:facebook, :instagram, :twitter, :google, :yahoo, :github, :persona, :cas)
|
||||||
end
|
end
|
||||||
|
|
||||||
# need to be able to call this
|
# need to be able to call this
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class InstagramUserInfo < ActiveRecord::Base
|
||||||
|
|
||||||
|
belongs_to :user
|
||||||
|
|
||||||
|
end
|
|
@ -882,6 +882,9 @@ en:
|
||||||
twitter:
|
twitter:
|
||||||
title: "with Twitter"
|
title: "with Twitter"
|
||||||
message: "Authenticating with Twitter (make sure pop up blockers are not enabled)"
|
message: "Authenticating with Twitter (make sure pop up blockers are not enabled)"
|
||||||
|
instagram:
|
||||||
|
title: "with Instagram"
|
||||||
|
message: "Authenticating with Instagram (make sure pop up blockers are not enabled)"
|
||||||
facebook:
|
facebook:
|
||||||
title: "with Facebook"
|
title: "with Facebook"
|
||||||
message: "Authenticating with Facebook (make sure pop up blockers are not enabled)"
|
message: "Authenticating with Facebook (make sure pop up blockers are not enabled)"
|
||||||
|
|
|
@ -939,6 +939,10 @@ en:
|
||||||
twitter_consumer_key: "Consumer key for Twitter authentication, registered at http://dev.twitter.com"
|
twitter_consumer_key: "Consumer key for Twitter authentication, registered at http://dev.twitter.com"
|
||||||
twitter_consumer_secret: "Consumer secret for Twitter authentication, registered at http://dev.twitter.com"
|
twitter_consumer_secret: "Consumer secret for Twitter authentication, registered at http://dev.twitter.com"
|
||||||
|
|
||||||
|
enable_instagram_logins: "Enable Instagram authentication, requires instagram_consumer_key and instagram_consumer_secret"
|
||||||
|
instagram_consumer_key: "Consumer key for Instagram authentication"
|
||||||
|
instagram_consumer_secret: "Consumer secret Instagram authentication"
|
||||||
|
|
||||||
enable_facebook_logins: "Enable Facebook authentication, requires facebook_app_id and facebook_app_secret"
|
enable_facebook_logins: "Enable Facebook authentication, requires facebook_app_id and facebook_app_secret"
|
||||||
facebook_app_id: "App id for Facebook authentication, registered at https://developers.facebook.com/apps"
|
facebook_app_id: "App id for Facebook authentication, registered at https://developers.facebook.com/apps"
|
||||||
facebook_app_secret: "App secret for Facebook authentication, registered at https://developers.facebook.com/apps"
|
facebook_app_secret: "App secret for Facebook authentication, registered at https://developers.facebook.com/apps"
|
||||||
|
|
|
@ -234,6 +234,15 @@ login:
|
||||||
twitter_consumer_secret:
|
twitter_consumer_secret:
|
||||||
default: ''
|
default: ''
|
||||||
regex: "^[a-zA-Z0-9_+-]+$"
|
regex: "^[a-zA-Z0-9_+-]+$"
|
||||||
|
enable_instagram_logins:
|
||||||
|
client: true
|
||||||
|
default: false
|
||||||
|
instagram_consumer_key:
|
||||||
|
default: ''
|
||||||
|
regex: "^[a-z0-9]+$"
|
||||||
|
instagram_consumer_secret:
|
||||||
|
default: ''
|
||||||
|
regex: "^[a-z0-9]+$"
|
||||||
enable_facebook_logins:
|
enable_facebook_logins:
|
||||||
client: true
|
client: true
|
||||||
default: false
|
default: false
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
class CreateInstagramUserInfos < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :instagram_user_infos do |t|
|
||||||
|
t.integer :user_id
|
||||||
|
t.string :screen_name
|
||||||
|
t.integer :instagram_user_id
|
||||||
|
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -7,3 +7,4 @@ require_dependency 'auth/open_id_authenticator'
|
||||||
require_dependency 'auth/github_authenticator'
|
require_dependency 'auth/github_authenticator'
|
||||||
require_dependency 'auth/twitter_authenticator'
|
require_dependency 'auth/twitter_authenticator'
|
||||||
require_dependency 'auth/google_oauth2_authenticator'
|
require_dependency 'auth/google_oauth2_authenticator'
|
||||||
|
require_dependency 'auth/instagram_authenticator'
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
class Auth::InstagramAuthenticator < Auth::Authenticator
|
||||||
|
|
||||||
|
def name
|
||||||
|
"instagram"
|
||||||
|
end
|
||||||
|
|
||||||
|
# TODO twitter provides all sorts of extra info, like website/bio etc.
|
||||||
|
# it may be worth considering pulling some of it in.
|
||||||
|
def after_authenticate(auth_token)
|
||||||
|
|
||||||
|
result = Auth::Result.new
|
||||||
|
|
||||||
|
data = auth_token[:info]
|
||||||
|
|
||||||
|
result.username = screen_name = data["nickname"]
|
||||||
|
result.name = name = data["name"]
|
||||||
|
instagram_user_id = auth_token["uid"]
|
||||||
|
|
||||||
|
result.extra_data = {
|
||||||
|
instagram_user_id: instagram_user_id,
|
||||||
|
instagram_screen_name: screen_name
|
||||||
|
}
|
||||||
|
|
||||||
|
user_info = InstagramUserInfo.find_by(instagram_user_id: instagram_user_id)
|
||||||
|
|
||||||
|
result.user = user_info.try(:user)
|
||||||
|
|
||||||
|
result
|
||||||
|
end
|
||||||
|
|
||||||
|
def after_create_account(user, auth)
|
||||||
|
data = auth[:extra_data]
|
||||||
|
InstagramUserInfo.create(
|
||||||
|
user_id: user.id,
|
||||||
|
screen_name: data[:instagram_screen_name],
|
||||||
|
instagram_user_id: data[:instagram_user_id]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def register_middleware(omniauth)
|
||||||
|
omniauth.provider :instagram,
|
||||||
|
:setup => lambda { |env|
|
||||||
|
strategy = env["omniauth.strategy"]
|
||||||
|
strategy.options[:client_id] = SiteSetting.instagram_consumer_key
|
||||||
|
strategy.options[:client_secret] = SiteSetting.instagram_consumer_secret
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in New Issue