forked from pelle/oauth-plugin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modularized OauthProvider generator, added appropriate hooks for orm,
test_framework and template, added generators for ActiveRecord, ERB, Haml, TestUnit and RSpec. Also removed trailing spaces from all templates, used in OauthPRovider generating.
- Loading branch information
1 parent
91e1362
commit ead01d2
Showing
55 changed files
with
671 additions
and
528 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require 'rails/generators/active_record' | ||
|
||
module ActiveRecord | ||
module Generators | ||
class OauthProviderGenerator < Rails::Generators::Base | ||
include Rails::Generators::Migration | ||
|
||
source_root File.expand_path('../templates', __FILE__) | ||
|
||
# Implement the required interface for Rails::Generators::Migration. | ||
def self.next_migration_number(dirname) #:nodoc: | ||
next_migration_number = current_migration_number(dirname) + 1 | ||
if ActiveRecord::Base.timestamped_migrations | ||
[Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max | ||
else | ||
"%.3d" % next_migration_number | ||
end | ||
end | ||
|
||
def check_class_collisions | ||
class_collisions '', %w(ClientApplication OauthNonce RequestToken AccessToken OauthToken) | ||
end | ||
|
||
def copy_models | ||
template 'client_application.rb', File.join('app/models', 'client_application.rb') | ||
template 'oauth_token.rb', File.join('app/models', 'oauth_token.rb') | ||
template 'request_token.rb', File.join('app/models', 'request_token.rb') | ||
template 'access_token.rb', File.join('app/models', 'access_token.rb') | ||
template 'oauth2_token.rb', File.join('app/models', 'oauth2_token.rb') | ||
template 'oauth2_verifier.rb', File.join('app/models', 'oauth2_verifier.rb') | ||
template 'oauth_nonce.rb', File.join('app/models', 'oauth_nonce.rb') | ||
end | ||
|
||
def copy_migration | ||
migration_template 'migration.rb', 'db/migrate/create_oauth_tables' | ||
end | ||
end | ||
end | ||
end |
8 changes: 4 additions & 4 deletions
8
.../oauth_provider/templates/access_token.rb → ...s/active_record/templates/access_token.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
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
1 change: 0 additions & 1 deletion
1
.../oauth_provider/templates/oauth2_token.rb → ...s/active_record/templates/oauth2_token.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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
class Oauth2Token < AccessToken | ||
|
||
def as_json(options={}) | ||
{:access_token=>token} | ||
end | ||
|
12 changes: 6 additions & 6 deletions
12
...uth_provider/templates/oauth2_verifier.rb → ...ctive_record/templates/oauth2_verifier.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 |
---|---|---|
@@ -1,28 +1,28 @@ | ||
class Oauth2Verifier < OauthToken | ||
validates_presence_of :user | ||
|
||
def exchange!(params={}) | ||
OauthToken.transaction do | ||
token = Oauth2Token.create! :user=>user,:client_application=>client_application | ||
invalidate! | ||
token | ||
end | ||
end | ||
|
||
def code | ||
token | ||
end | ||
|
||
def redirect_url | ||
callback_url | ||
end | ||
|
||
protected | ||
|
||
def generate_keys | ||
self.token = OAuth::Helper.generate_key(20)[0,20] | ||
self.valid_to = 10.minutes.from_now | ||
self.authorized_at = Time.now | ||
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
16 changes: 8 additions & 8 deletions
16
...oauth_provider/templates/request_token.rb → .../active_record/templates/request_token.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 |
---|---|---|
@@ -1,40 +1,40 @@ | ||
class RequestToken < OauthToken | ||
|
||
attr_accessor :provided_oauth_verifier | ||
|
||
def authorize!(user) | ||
return false if authorized? | ||
self.user = user | ||
self.authorized_at = Time.now | ||
self.verifier=OAuth::Helper.generate_key(20)[0,20] unless oauth10? | ||
self.save | ||
end | ||
|
||
def exchange! | ||
return false unless authorized? | ||
return false unless oauth10? || verifier==provided_oauth_verifier | ||
|
||
RequestToken.transaction do | ||
access_token = AccessToken.create(:user => user, :client_application => client_application) | ||
invalidate! | ||
access_token | ||
end | ||
end | ||
|
||
def to_query | ||
if oauth10? | ||
super | ||
else | ||
"#{super}&oauth_callback_confirmed=true" | ||
end | ||
end | ||
|
||
def oob? | ||
self.callback_url=='oob' | ||
end | ||
|
||
def oauth10? | ||
(defined? OAUTH_10_SUPPORT) && OAUTH_10_SUPPORT && self.callback_url.blank? | ||
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,21 @@ | ||
require 'rails/generators/erb' | ||
|
||
module Erb | ||
module Generators | ||
class OauthProviderGenerator < Erb::Generators::Base | ||
source_root File.expand_path('../templates', __FILE__) | ||
|
||
def copy_view_files | ||
template '_form.html.erb', File.join('app/views', class_path, 'oauth_clients', '_form.html.erb') | ||
template 'new.html.erb', File.join('app/views', class_path, 'oauth_clients', 'new.html.erb') | ||
template 'index.html.erb', File.join('app/views', class_path, 'oauth_clients', 'index.html.erb') | ||
template 'show.html.erb', File.join('app/views', class_path, 'oauth_clients', 'show.html.erb') | ||
template 'edit.html.erb', File.join('app/views', class_path, 'oauth_clients', 'edit.html.erb') | ||
template 'authorize.html.erb', File.join('app/views', class_path, file_name, 'authorize.html.erb') | ||
template 'oauth2_authorize.html.erb', File.join('app/views', class_path, file_name, 'oauth2_authorize.html.erb') | ||
template 'authorize_success.html.erb', File.join('app/views', class_path, file_name, 'authorize_success.html.erb') | ||
template 'authorize_failure.html.erb', File.join('app/views', class_path, file_name, 'authorize_failure.html.erb') | ||
end | ||
end | ||
end | ||
end |
File renamed without changes.
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 |
---|---|---|
|
@@ -11,4 +11,4 @@ | |
<p> | ||
<%%= submit_tag %> | ||
</p> | ||
<%% end %> | ||
<%% end %> |
File renamed without changes.
File renamed without changes.
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
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
File renamed without changes.
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,28 @@ | ||
require 'rails/generators/erb/controller/controller_generator' | ||
|
||
module Haml | ||
module Generators | ||
class OauthProviderGenerator < Erb::Generators::Base | ||
source_root File.expand_path('../templates', __FILE__) | ||
|
||
argument :name, :type => :string, :default => 'Oauth' | ||
|
||
def copy_view_files | ||
template '_form.html.haml', File.join('app/views', class_path, 'oauth_clients', '_form.html.haml') | ||
template 'new.html.haml', File.join('app/views', class_path, 'oauth_clients', 'new.html.haml') | ||
template 'index.html.haml', File.join('app/views', class_path, 'oauth_clients', 'index.html.haml') | ||
template 'show.html.haml', File.join('app/views', class_path, 'oauth_clients', 'show.html.haml') | ||
template 'edit.html.haml', File.join('app/views', class_path, 'oauth_clients', 'edit.html.haml') | ||
template 'authorize.html.haml', File.join('app/views', class_path, file_name, 'authorize.html.haml') | ||
template 'oauth2_authorize.html.haml', File.join('app/views', class_path, file_name, 'oauth2_authorize.html.haml') | ||
template 'authorize_success.html.haml', File.join('app/views', class_path, file_name, 'authorize_success.html.haml') | ||
template 'authorize_failure.html.haml', File.join('app/views', class_path, file_name, 'authorize_failure.html.haml') | ||
end | ||
|
||
protected | ||
def handler | ||
:haml | ||
end | ||
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.