Commit e3002da5 authored by Koza's avatar Koza
Browse files

Add Omniauth-Authsch gem & remove old rails project

parent 86156ba2
......@@ -4,6 +4,7 @@ Az [AuthSCH oldalhoz](https://git.sch.bme.hu/kszk/authsch) különböző nyelven
## Támogatott nyelvek
* PHP5
* Ruby on Rails
* [Omniauth-Authsch gem](https://github.com/kiskoza/omniauth-authsch)
## Kötelező ezeket használnom?
Nem, de megkérnénk hogy ha olyan nyelven írsz klienst, amit nem látsz felsorolva, akkor merge request-tel "küldd be" a projekthez, hogy másnak ne kelljen újra megírnia.
\ No newline at end of file
== README
Ez egy teljes project, egy mkd rails alkalmazs ahhoz, hogy legyen min fejleszteni tesztelni a rails klienst. Sajt alkalmazs ksztshez kvesd a lentebbi utastsokat.
== Hasznlat
Elszr is kell devise, omniauth s omniauth-oauth2 gem a Gemfileba.
Nagyjbl ezt a tutorialt lehet kvetni: https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
Deviseban generlunk sajt usert:
```
rails generate devise:install
rails generate devise User
```
(User helyett brmi lehet)
Ezutn kiegsztjk ezt a modellt s migrlunk is:
```
rails g migration AddColumnsToUsers provider uid
rake db:migrate
```
config/initializers/devise.rb:
```ruby
config.omniauth :sch, 'APP_ID','APP_SECRET',scope: 'basic mail'
```
ha mr abban a mappban vagyunk, ebbl a projectbl a config/initializers/sch.rb -t msoljuk is t
config/roots.rb:
```ruby
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
```
(Ha fent nem User-t hoztunk ltre akkor ezt is rtelemszeren mdostani kell!)
app/controllers/users/omniauth_callbacks_controller.rb:
legegyszerbb msolni innen gy ahogy van, rdekldk elolvashatjk az Overview-s linket
app/models/user.rb:
Lnyegben msolhat, nincs benne nagy varzslat, a kt fggvny ami benne van az kell ahhoz hogy mkdjn, ugyancsak a fentebbi linkbl megrthet.
Ezzel elvileg a keret fel van ptve. rdemes mg egy olyan view-al rendelkezni amin le is lehet tesztelni a dolgot:
```ruby
<% if user_signed_in? %>
<%= current_user.email%>
<br>
<%= link_to('Logout', destroy_user_session_path, :method=>'delete') %>
<% else %>
<%= link_to "Sign in with SCH", user_omniauth_authorize_path(:sch) %>
<% end %>
```
Ha csak bejelentkezs utn akarsz tartalmat mutatni, akkor config/roots.rb:
```ruby
devise_scope :user do
authenticated :user do
root 'base#index2', as: :authenticated_root
end
unauthenticated do
root 'base#index', as: :unauthenticated_root
end
end
```
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'
# Ignore bundler config.
/.bundle
# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin]
# Better errors
gem 'better_errors', '~> 1.1.0'
# Hibakezel konzolhoz
gem 'binding_of_caller', '~> 0.7.2'
# devise loginhoz
gem 'devise'
gem 'omniauth'
gem 'omniauth-oauth2'
\ No newline at end of file
GEM
remote: https://rubygems.org/
specs:
actionmailer (4.1.1)
actionpack (= 4.1.1)
actionview (= 4.1.1)
mail (~> 2.5.4)
actionpack (4.1.1)
actionview (= 4.1.1)
activesupport (= 4.1.1)
rack (~> 1.5.2)
rack-test (~> 0.6.2)
actionview (4.1.1)
activesupport (= 4.1.1)
builder (~> 3.1)
erubis (~> 2.7.0)
activemodel (4.1.1)
activesupport (= 4.1.1)
builder (~> 3.1)
activerecord (4.1.1)
activemodel (= 4.1.1)
activesupport (= 4.1.1)
arel (~> 5.0.0)
activesupport (4.1.1)
i18n (~> 0.6, >= 0.6.9)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 1.1)
arel (5.0.1.20140414130214)
bcrypt (3.1.7-x86-mingw32)
better_errors (1.1.0)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
builder (3.2.2)
coderay (1.1.0)
coffee-rails (4.0.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
coffee-script (2.3.0)
coffee-script-source
execjs
coffee-script-source (1.7.1)
debug_inspector (0.0.2)
devise (3.2.4)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 3.2.6, < 5)
thread_safe (~> 0.1)
warden (~> 1.2.3)
erubis (2.7.0)
execjs (2.2.1)
faraday (0.9.0)
multipart-post (>= 1.2, < 3)
hashie (3.2.0)
hike (1.2.3)
i18n (0.6.11)
jbuilder (2.1.3)
activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2)
jquery-rails (3.1.1)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.8.1)
jwt (1.0.0)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.25.1)
minitest (5.4.0)
multi_json (1.10.1)
multi_xml (0.5.5)
multipart-post (2.0.0)
oauth2 (1.0.0)
faraday (>= 0.8, < 0.10)
jwt (~> 1.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (~> 1.2)
omniauth (1.2.2)
hashie (>= 1.2, < 4)
rack (~> 1.0)
omniauth-oauth2 (1.2.0)
faraday (>= 0.8, < 0.10)
multi_json (~> 1.3)
oauth2 (~> 1.0)
omniauth (~> 1.2)
orm_adapter (0.5.0)
polyglot (0.3.5)
rack (1.5.2)
rack-test (0.6.2)
rack (>= 1.0)
rails (4.1.1)
actionmailer (= 4.1.1)
actionpack (= 4.1.1)
actionview (= 4.1.1)
activemodel (= 4.1.1)
activerecord (= 4.1.1)
activesupport (= 4.1.1)
bundler (>= 1.3.0, < 2.0)
railties (= 4.1.1)
sprockets-rails (~> 2.0)
railties (4.1.1)
actionpack (= 4.1.1)
activesupport (= 4.1.1)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.3.2)
rdoc (4.1.1)
json (~> 1.4)
sass (3.2.19)
sass-rails (4.0.3)
railties (>= 4.0.0, < 5.0)
sass (~> 3.2.0)
sprockets (~> 2.8, <= 2.11.0)
sprockets-rails (~> 2.0)
sdoc (0.4.0)
json (~> 1.8)
rdoc (~> 4.0, < 5.0)
sprockets (2.11.0)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.1.3)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (~> 2.8)
sqlite3 (1.3.9-x86-mingw32)
thor (0.19.1)
thread_safe (0.3.4)
tilt (1.4.1)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
turbolinks (2.2.2)
coffee-rails
tzinfo (1.2.1)
thread_safe (~> 0.1)
tzinfo-data (1.2014.5)
tzinfo (>= 1.0.0)
uglifier (2.5.3)
execjs (>= 0.3.0)
json (>= 1.8.0)
warden (1.2.3)
rack (>= 1.0)
PLATFORMS
x86-mingw32
DEPENDENCIES
better_errors (~> 1.1.0)
binding_of_caller (~> 0.7.2)
coffee-rails (~> 4.0.0)
devise
jbuilder (~> 2.0)
jquery-rails
omniauth
omniauth-oauth2
rails (= 4.1.1)
sass-rails (~> 4.0.3)
sdoc (~> 0.4.0)
sqlite3
turbolinks
tzinfo-data
uglifier (>= 1.3.0)
## README
Ez egy teljes project, egy működő rails alkalmazás ahhoz, hogy legyen min fejleszteni tesztelni a rails klienst. Saját alkalmazás készítéséhez kövesd a lentebbi utasításokat.
## Használat
Először is kell devise, omniauth és omniauth-oauth2 gem a Gemfileba.
Nagyjából ezt a tutorialt lehet követni: https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
Deviseban generálunk saját usert:
```
rails generate devise:install
rails generate devise User
```
(User helyett bármi lehet)
Ezután kiegészítjük ezt a modellt és migrálunk is:
```
rails g migration AddColumnsToUsers provider uid
rake db:migrate
```
config/initializers/devise.rb:
```ruby
config.omniauth :sch, 'APP_ID','APP_SECRET',scope: 'basic mail'
```
ha már abban a mappában vagyunk, ebből a projectből a config/initializers/sch.rb -t másoljuk is át
config/roots.rb:
```ruby
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
```
(Ha fent nem User-t hoztunk létre akkor ezt is értelemszerűen módosítani kell!)
app/controllers/users/omniauth_callbacks_controller.rb:
legegyszerűbb másolni innen úgy ahogy van, érdeklődők elolvashatják az Overview-s linket
app/models/user.rb:
Lényegében másolható, nincs benne nagy varázslat, a két függvény ami benne van az kell ahhoz hogy működjön, ugyancsak a fentebbi linkből megérthető.
Ezzel elvileg a keret fel van építve. Érdemes még egy olyan view-al rendelkezni amin le is lehet tesztelni a dolgot:
```ruby
<% if user_signed_in? %>
<%= current_user.email%>
<br>
<%= link_to('Logout', destroy_user_session_path, :method=>'delete') %>
<% else %>
<%= link_to "Sign in with SCH", user_omniauth_authorize_path(:sch) %>
<% end %>
```
Ha csak bejelentkezés után akarsz tartalmat mutatni, akkor config/roots.rb:
```ruby
devise_scope :user do
authenticated :user do
root 'base#index2', as: :authenticated_root
end
unauthenticated do
root 'base#index', as: :unauthenticated_root
end
end
```
## SSL Windows alatt
* https://gist.github.com/fnichol/867550
\ No newline at end of file
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
Rails.application.load_tasks
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any styles
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_tree .
*= require_self
*/
// Place all the styles related to the base controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
end
class BaseController < ApplicationController
def index
end
def index2
end
end
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def sch
#debug
# You need to implement the method below in your model (e.g. app/models/user.rb)
@user = User.from_omniauth(request.env["omniauth.auth"])
if @user.persisted?
sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
set_flash_message(:notice, :success, :kind => "SCH") if is_navigational_format?
else
session["devise.sch_data"] = request.env["omniauth.auth"]
redirect_to 'base#index2'
end
end
def action_missing(provider)
# Set up authentication/authorizations here, and distribute tasks
# that are provider specific to other methods, leaving only tasks
# that work across all providers in this method.
end
end
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment