Experimental authentication for Launchpad and Google added

This commit is contained in:
Christoph Haas 2017-04-06 12:56:06 +02:00
parent 0c080386ef
commit 9a5ddb5e13
8 changed files with 154 additions and 44 deletions

View file

@ -2,11 +2,38 @@ class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable,
# :registerable,
# :recoverable,
:registerable,
:recoverable,
# :rememberable,
:trackable,
:validatable,
:timeoutable,
:lockable
:lockable,
:omniauthable, :omniauth_providers => [:google_oauth2, :launchpad]
# :omniauthable, :omniauth_providers => [:launchpad, :google]
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.email = auth.info.email
user.password = Devise.friendly_token[0,20]
end
end
#
# def self.from_omniauth(access_token)
# data = access_token.info
# user = User.where(:email => data["email"]).first
#
# # Uncomment the section below if you want users to be created if they don't exist
# # unless user
# # user = User.create(name: data["name"],
# # email: data["email"],
# # password: Devise.friendly_token[0,20]
# # )
# # end
# user
# end
end

View file

@ -20,12 +20,20 @@
.small-6.columns
= f.password_field :password, autocomplete: "off"
- if devise_mapping.rememberable?
.small-6.columns
= f.check_box :remember_me
.small-6.columns
= f.label :remember_me
/ - if devise_mapping.rememberable?
/ .small-6.columns
/ = f.check_box :remember_me
/ .small-6.columns
/ = f.label :remember_me
= f.submit "Log in", class: 'button'
= render "devise/shared/links"
/ = render "devise/shared/links"
/ h1 Experimental SSL certificate Debian SSO auth
/
/ = link_to 'log in using your secure certificate', users_debian_sso_path
/ = link_to "Sign in with Launchpad", user_launchpad_omniauth_authorize_path
= link_to "Sign in with Google", user_google_oauth2_omniauth_authorize_path
= link_to "Sign in with Launchpad", user_launchpad_omniauth_authorize_path