xing_backend_token_auth 0.1.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +13 -0
  3. data/README.md +679 -0
  4. data/Rakefile +34 -0
  5. data/app/controllers/devise_token_auth/application_controller.rb +22 -0
  6. data/app/controllers/devise_token_auth/concerns/set_user_by_token.rb +110 -0
  7. data/app/controllers/devise_token_auth/confirmations_controller.rb +31 -0
  8. data/app/controllers/devise_token_auth/omniauth_callbacks_controller.rb +169 -0
  9. data/app/controllers/devise_token_auth/passwords_controller.rb +107 -0
  10. data/app/controllers/devise_token_auth/registrations_controller.rb +99 -0
  11. data/app/controllers/devise_token_auth/sessions_controller.rb +50 -0
  12. data/app/controllers/devise_token_auth/token_validations_controller.rb +22 -0
  13. data/app/serializers/devise_token_auth/error_messages_serializer.rb +16 -0
  14. data/app/serializers/devise_token_auth/resource_errors_serializer.rb +24 -0
  15. data/app/serializers/devise_token_auth/resource_serializer.rb +17 -0
  16. data/app/serializers/devise_token_auth/success_message_serializer.rb +15 -0
  17. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  18. data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  19. data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  20. data/app/views/devise_token_auth/omniauth_failure.html.erb +2 -0
  21. data/app/views/devise_token_auth/omniauth_success.html.erb +8 -0
  22. data/app/views/layouts/omniauth_response.html.erb +31 -0
  23. data/config/initializers/devise.rb +207 -0
  24. data/config/initializers/token_auth_failure_app.rb +7 -0
  25. data/config/locales/devise.en.yml +59 -0
  26. data/config/routes.rb +5 -0
  27. data/lib/devise_token_auth.rb +9 -0
  28. data/lib/devise_token_auth/controllers/helpers.rb +129 -0
  29. data/lib/devise_token_auth/controllers/url_helpers.rb +8 -0
  30. data/lib/devise_token_auth/engine.rb +32 -0
  31. data/lib/devise_token_auth/models/token_authenticatable.rb +195 -0
  32. data/lib/devise_token_auth/rails/routes.rb +65 -0
  33. data/lib/generators/devise_token_auth/USAGE +31 -0
  34. data/lib/generators/devise_token_auth/install_generator.rb +100 -0
  35. data/lib/generators/devise_token_auth/install_views_generator.rb +16 -0
  36. data/lib/generators/devise_token_auth/templates/devise_token_auth.rb +22 -0
  37. data/lib/generators/devise_token_auth/templates/devise_token_auth_add_token_info_to_users.rb.erb +14 -0
  38. data/lib/tasks/devise_token_auth_tasks.rake +4 -0
  39. data/lib/xing_backend_token_auth.rb +1 -0
  40. data/test/controllers/demo_group_controller_test.rb +126 -0
  41. data/test/controllers/demo_mang_controller_test.rb +263 -0
  42. data/test/controllers/demo_user_controller_test.rb +262 -0
  43. data/test/controllers/devise_token_auth/confirmations_controller_test.rb +107 -0
  44. data/test/controllers/devise_token_auth/omniauth_callbacks_controller_test.rb +144 -0
  45. data/test/controllers/devise_token_auth/passwords_controller_test.rb +275 -0
  46. data/test/controllers/devise_token_auth/registrations_controller_test.rb +405 -0
  47. data/test/controllers/devise_token_auth/registrations_controller_test.rb.orig +494 -0
  48. data/test/controllers/devise_token_auth/sessions_controller_test.rb +169 -0
  49. data/test/controllers/overrides/confirmations_controller_test.rb +44 -0
  50. data/test/controllers/overrides/omniauth_callbacks_controller_test.rb +44 -0
  51. data/test/controllers/overrides/passwords_controller_test.rb +64 -0
  52. data/test/controllers/overrides/registrations_controller_test.rb +42 -0
  53. data/test/controllers/overrides/sessions_controller_test.rb +35 -0
  54. data/test/controllers/overrides/token_validations_controller_test.rb +38 -0
  55. data/test/dummy/README.rdoc +28 -0
  56. data/test/dummy/Rakefile +6 -0
  57. data/test/dummy/app/assets/images/logo.jpg +0 -0
  58. data/test/dummy/app/assets/images/omniauth-provider-settings.png +0 -0
  59. data/test/dummy/app/assets/javascripts/application.js +13 -0
  60. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  61. data/test/dummy/app/controllers/application_controller.rb +16 -0
  62. data/test/dummy/app/controllers/demo_group_controller.rb +13 -0
  63. data/test/dummy/app/controllers/demo_mang_controller.rb +12 -0
  64. data/test/dummy/app/controllers/demo_user_controller.rb +12 -0
  65. data/test/dummy/app/controllers/overrides/confirmations_controller.rb +32 -0
  66. data/test/dummy/app/controllers/overrides/omniauth_callbacks_controller.rb +14 -0
  67. data/test/dummy/app/controllers/overrides/passwords_controller.rb +39 -0
  68. data/test/dummy/app/controllers/overrides/registrations_controller.rb +27 -0
  69. data/test/dummy/app/controllers/overrides/sessions_controller.rb +26 -0
  70. data/test/dummy/app/controllers/overrides/token_validations_controller.rb +23 -0
  71. data/test/dummy/app/controllers/registrations_controller.rb +2 -0
  72. data/test/dummy/app/helpers/application_helper.rb +1065 -0
  73. data/test/dummy/app/models/evil_user.rb +5 -0
  74. data/test/dummy/app/models/mang.rb +5 -0
  75. data/test/dummy/app/models/user.rb +20 -0
  76. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  77. data/test/dummy/bin/bundle +3 -0
  78. data/test/dummy/bin/rails +8 -0
  79. data/test/dummy/bin/rake +8 -0
  80. data/test/dummy/bin/spring +18 -0
  81. data/test/dummy/config.ru +16 -0
  82. data/test/dummy/config/application.rb +23 -0
  83. data/test/dummy/config/boot.rb +5 -0
  84. data/test/dummy/config/database.yml +31 -0
  85. data/test/dummy/config/environment.rb +5 -0
  86. data/test/dummy/config/environments/development.rb +44 -0
  87. data/test/dummy/config/environments/production.rb +82 -0
  88. data/test/dummy/config/environments/test.rb +40 -0
  89. data/test/dummy/config/initializers/assets.rb +8 -0
  90. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  91. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  92. data/test/dummy/config/initializers/devise_token_auth.rb +22 -0
  93. data/test/dummy/config/initializers/figaro.rb +1 -0
  94. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  95. data/test/dummy/config/initializers/inflections.rb +16 -0
  96. data/test/dummy/config/initializers/mime_types.rb +4 -0
  97. data/test/dummy/config/initializers/omniauth.rb +8 -0
  98. data/test/dummy/config/initializers/session_store.rb +3 -0
  99. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  100. data/test/dummy/config/locales/en.yml +23 -0
  101. data/test/dummy/config/routes.rb +32 -0
  102. data/test/dummy/config/secrets.yml +22 -0
  103. data/test/dummy/config/spring.rb +1 -0
  104. data/test/dummy/db/migrate/20140715061447_devise_token_auth_create_users.rb +56 -0
  105. data/test/dummy/db/migrate/20140715061805_devise_token_auth_create_mangs.rb +56 -0
  106. data/test/dummy/db/migrate/20140829044006_add_operating_thetan_to_user.rb +6 -0
  107. data/test/dummy/db/migrate/20140916224624_add_favorite_color_to_mangs.rb +5 -0
  108. data/test/dummy/db/migrate/20140928231203_devise_token_auth_create_evil_users.rb +57 -0
  109. data/test/dummy/db/schema.rb +111 -0
  110. data/test/dummy/public/404.html +67 -0
  111. data/test/dummy/public/422.html +67 -0
  112. data/test/dummy/public/500.html +66 -0
  113. data/test/dummy/public/favicon.ico +0 -0
  114. data/test/fixtures/evil_users.yml +29 -0
  115. data/test/fixtures/mangs.yml +29 -0
  116. data/test/fixtures/users.yml +29 -0
  117. data/test/integration/navigation_test.rb +10 -0
  118. data/test/lib/generators/devise_token_auth/install_generator_test.rb +131 -0
  119. data/test/lib/generators/devise_token_auth/install_views_generator_test.rb +23 -0
  120. data/test/models/user_test.rb +81 -0
  121. data/test/test_helper.rb +60 -0
  122. metadata +320 -0
@@ -0,0 +1,99 @@
1
+ module DeviseTokenAuth
2
+ class RegistrationsController < DeviseTokenAuth::ApplicationController
3
+
4
+ before_filter :set_user_by_token, :only => [:destroy, :update]
5
+ skip_after_filter :update_auth_header, :only => [:create, :destroy]
6
+
7
+ respond_to :json
8
+
9
+ def create
10
+ build_resource(sign_up_params)
11
+
12
+ resource.uid = sign_up_params[resource_class.authentication_keys.first]
13
+
14
+ # success redirect url is required
15
+ unless !defined?(resource.confirmed?) or params[:confirm_success_url]
16
+ return render json: {
17
+ status: 'error',
18
+ data: resource,
19
+ errors: ["Missing `confirm_success_url` param."]
20
+ }, status: 403
21
+ end
22
+
23
+ begin
24
+ # override email confirmation, must be sent manually from ctrl
25
+ User.skip_callback("create", :after, :send_on_create_confirmation_instructions)
26
+
27
+ if resource.save
28
+ if defined?(resource.confirmed?) and !resource.confirmed?
29
+ resource.send_confirmation_instructions({
30
+ client_config: params[:config_name],
31
+ redirect_url: params[:confirm_success_url]
32
+ })
33
+ else
34
+ # email auth has been bypassed, authenticate user
35
+ @user = resource
36
+ @client_id = SecureRandom.urlsafe_base64(nil, false)
37
+ @token = SecureRandom.urlsafe_base64(nil, false)
38
+
39
+ @user.tokens[@client_id] = {
40
+ token: BCrypt::Password.create(@token),
41
+ expiry: (Time.now + DeviseTokenAuth.token_lifespan).to_i
42
+ }
43
+
44
+ @user.save!
45
+
46
+ update_auth_header
47
+ end
48
+
49
+ render json: resource_serializer(resource)
50
+ else
51
+ clean_up_passwords resource
52
+ render json: error_serializer(resource), status: 403
53
+ end
54
+ rescue ActiveRecord::RecordNotUnique
55
+ clean_up_passwords resource
56
+ render json: error_serializer(resource, "An account already exists for #{resource.send(resource_class.authentication_keys.first)}"), status: 403
57
+ end
58
+ end
59
+
60
+ def update
61
+ if @user
62
+ if @user.update_attributes(account_update_params)
63
+ render json: resource_serializer(@user)
64
+ else
65
+ render json: error_serializer(@user), status: 403
66
+ end
67
+ else
68
+ render json: error_messages("User not found."), status: 404
69
+ end
70
+ end
71
+
72
+ def destroy
73
+ if @user
74
+ @user.destroy
75
+
76
+ render json: success_message("Account with uid #{@user.uid} has been destroyed.")
77
+ else
78
+ render json: error_messages("Unable to locate account for destruction."), status: 404
79
+ end
80
+ end
81
+
82
+ def build_resource(hash=nil)
83
+ self.resource = resource_class.new_with_session(hash || {}, session)
84
+ end
85
+
86
+ def sign_up_params
87
+ devise_parameter_sanitizer.sanitize(:sign_up)
88
+ end
89
+
90
+ def account_update_params
91
+ devise_parameter_sanitizer.sanitize(:account_update)
92
+ end
93
+
94
+ def resource_serializer(user)
95
+ serializer = DeviseTokenAuth.registration_serializer || ResourceSerializer
96
+ serializer.new(user)
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,50 @@
1
+ # see http://www.emilsoman.com/blog/2013/05/18/building-a-tested/
2
+ module DeviseTokenAuth
3
+ class SessionsController < DeviseTokenAuth::ApplicationController
4
+ before_filter :set_user_by_token, :only => [:destroy]
5
+ prepend_before_filter :allow_params_authentication!, only: :create
6
+ prepend_before_filter only: [ :create, :destroy ] { request.env["devise.skip_timeout"] = true }
7
+
8
+ def create
9
+ self.resource = warden.authenticate!(auth_options)
10
+ sign_in(resource_name, resource, :store => false)
11
+ @user = resource
12
+ @client_id = SecureRandom.urlsafe_base64(nil, false)
13
+ @token = SecureRandom.urlsafe_base64(nil, false)
14
+
15
+ @user.tokens[@client_id] = {
16
+ token: BCrypt::Password.create(@token),
17
+ expiry: (Time.now + DeviseTokenAuth.token_lifespan).to_i
18
+ }
19
+ @user.save
20
+ yield resource if block_given?
21
+ render json: resource_serializer(resource)
22
+ end
23
+
24
+ def auth_options
25
+ { scope: resource_name, recall: "#{controller_path}#new" }
26
+ end
27
+
28
+ def destroy
29
+ # remove auth instance variables so that after_filter does not run
30
+ user = remove_instance_variable(:@user) if @user
31
+ client_id = remove_instance_variable(:@client_id) if @client_id
32
+ remove_instance_variable(:@token) if @token
33
+
34
+ if user and client_id and user.tokens[client_id]
35
+ user.tokens.delete(client_id)
36
+ user.save!
37
+
38
+ render json: success_message, status: 200
39
+
40
+ else
41
+ render json: error_messages("User was not found or was not logged in."), status: 404
42
+ end
43
+ end
44
+
45
+ def resource_serializer(user)
46
+ serializer = DeviseTokenAuth.session_serializer || ResourceSerializer
47
+ serializer.new(user)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,22 @@
1
+ module DeviseTokenAuth
2
+ class TokenValidationsController < DeviseTokenAuth::ApplicationController
3
+ skip_before_filter :assert_is_devise_resource!, :only => [:validate_token]
4
+ before_filter :set_user_by_token, :only => [:validate_token]
5
+
6
+ def validate_token
7
+ # @user will have been set by set_user_token concern
8
+ if @user
9
+ render json: resource_serializer(@user)
10
+ else
11
+ render json: error_messages("Invalid login credentials"), status: 401
12
+ end
13
+ end
14
+
15
+
16
+ def resource_serializer(user)
17
+ serializer = DeviseTokenAuth.token_validation_serializer || ResourceSerializer
18
+ serializer.new(user)
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ module DeviseTokenAuth
2
+ class ErrorMessagesSerializer
3
+ def initialize(*args)
4
+ @args = args
5
+ end
6
+
7
+ attr_reader :args
8
+
9
+ def as_json(options)
10
+ {
11
+ status: 'error',
12
+ errors: args
13
+ }
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ module DeviseTokenAuth
2
+ class ResourceErrorsSerializer
3
+ def initialize(*args)
4
+ @args = args
5
+ end
6
+
7
+ attr_reader :args
8
+
9
+ def as_json(options)
10
+ resource = args[0]
11
+ response = {
12
+ status: "error",
13
+ data: resource.as_json(except: [:tokens, :created_at, :updated_at])
14
+ }
15
+ if args.length > 1
16
+ args.shift
17
+ response[:errors] = args
18
+ else
19
+ response[:errors] = resource.errors.to_hash.merge(full_messages: resource.errors.full_messages)
20
+ end
21
+ response
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ module DeviseTokenAuth
2
+
3
+ class ResourceSerializer
4
+ def initialize(resource)
5
+ @resource = resource
6
+ end
7
+ attr_reader :resource
8
+
9
+ def as_json(options)
10
+ {
11
+ status: "success",
12
+ data: resource.as_json(except: [:tokens, :created_at, :updated_at])
13
+ }
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ module DeviseTokenAuth
2
+ class SuccessMessageSerializer
3
+ def initialize(message)
4
+ @message = message
5
+ end
6
+
7
+ attr_reader :message
8
+
9
+ def as_json(options)
10
+ json_response = { status: 'success' }
11
+ json_response[:message] = message if message
12
+ json_response
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ <p>Welcome <%= @email %>!</p>
2
+
3
+ <p>You can confirm your account email through the link below:</p>
4
+
5
+ <p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token, config: message['client-config'].to_s, redirect_url: message['redirect-url']) %></p>
@@ -0,0 +1,8 @@
1
+ <p>Hello <%= @resource.email %>!</p>
2
+
3
+ <p>Someone has requested a link to change your password. You can do this through the link below.</p>
4
+
5
+ <p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token, config: message['client-config'].to_s, redirect_url: message['redirect-url'].to_s) %></p>
6
+
7
+ <p>If you didn't request this, please ignore this email.</p>
8
+ <p>Your password won't change until you access the link above and create a new one.</p>
@@ -0,0 +1,7 @@
1
+ <p>Hello <%= @resource.email %>!</p>
2
+
3
+ <p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>
4
+
5
+ <p>Click the link below to unlock your account:</p>
6
+
7
+ <p><%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %></p>
@@ -0,0 +1,2 @@
1
+ message: "authFailure",
2
+ error: "<%= @error %>"
@@ -0,0 +1,8 @@
1
+ <% @user.as_json.each do |attr, val| %>
2
+ "<%= attr %>": "<%= val %>",
3
+ <% end %>
4
+
5
+ "auth_token": "<%= @token %>",
6
+ "message": "deliverCredentials",
7
+ "client_id": "<%= @client_id %>",
8
+ "expiry": "<%= @expiry %>"
@@ -0,0 +1,31 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <script>
5
+ var usingExternalWindow = function() {
6
+ var nav = navigator.userAgent.toLowerCase(),
7
+ ieLTE10 = (nav && nav.indexOf('msie') != -1),
8
+ ie11 = !!navigator.userAgent.match(/Trident.*rv\:11\./);
9
+ return !(ieLTE10 || ie11);
10
+ }
11
+
12
+ if (usingExternalWindow()) {
13
+ window.addEventListener("message", function(ev) {
14
+ if (ev.data === "requestCredentials") {
15
+ ev.source.postMessage({
16
+ <%= yield %>
17
+ }, '*');
18
+ window.close();
19
+ }
20
+ });
21
+ } else {
22
+ window.location.href = "<%= @auth_origin_url %>";
23
+ }
24
+ </script>
25
+ </head>
26
+ <body>
27
+ <pre>
28
+ Redirecting...
29
+ </pre>
30
+ </body>
31
+ </html>
@@ -0,0 +1,207 @@
1
+ # Use this hook to configure devise mailer, warden hooks and so forth.
2
+ # Many of these configuration options can be set straight in your model.
3
+ Devise.setup do |config|
4
+ # The secret key used by Devise. Devise uses this key to generate
5
+ # random tokens. Changing this key will render invalid all existing
6
+ # confirmation, reset password and unlock tokens in the database.
7
+ # config.secret_key = 'd029dbc7262359b4f9906ec029bae825981dee112d9a1425643719765c8fd4884f12a37add35607fa3fa2d6fa6945a0077d7fe0f10a67f8ee66d69e9cc6ac19b'
8
+
9
+ # ==> Mailer Configuration
10
+ # Configure the e-mail address which will be shown in Devise::Mailer,
11
+ # note that it will be overwritten if you use your own mailer class
12
+ # with default "from" parameter.
13
+ config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'
14
+
15
+ # Configure the class responsible to send e-mails.
16
+ # config.mailer = 'Devise::Mailer'
17
+
18
+ # ==> ORM configuration
19
+ # Load and configure the ORM. Supports :active_record (default) and
20
+ # :mongoid (bson_ext recommended) by default. Other ORMs may be
21
+ # available as additional gems.
22
+ require 'devise/orm/active_record'
23
+
24
+ # ==> Configuration for any authentication mechanism
25
+ # Configure which keys are used when authenticating a user. The default is
26
+ # just :email. You can configure it to use [:username, :subdomain], so for
27
+ # authenticating a user, both parameters are required. Remember that those
28
+ # parameters are used only when authenticating and not when retrieving from
29
+ # session. If you need permissions, you should implement that in a before filter.
30
+ # You can also supply a hash where the value is a boolean determining whether
31
+ # or not authentication should be aborted when the value is not present.
32
+ # config.authentication_keys = [ :email ]
33
+
34
+ # Configure parameters from the request object used for authentication. Each entry
35
+ # given should be a request method and it will automatically be passed to the
36
+ # find_for_authentication method and considered in your model lookup. For instance,
37
+ # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
38
+ # The same considerations mentioned for authentication_keys also apply to request_keys.
39
+ # config.request_keys = []
40
+
41
+ # Configure which authentication keys should be case-insensitive.
42
+ # These keys will be downcased upon creating or modifying a user and when used
43
+ # to authenticate or find a user. Default is :email.
44
+ config.case_insensitive_keys = [ :email ]
45
+
46
+ # Configure which authentication keys should have whitespace stripped.
47
+ # These keys will have whitespace before and after removed upon creating or
48
+ # modifying a user and when used to authenticate or find a user. Default is :email.
49
+ config.strip_whitespace_keys = [ :email ]
50
+
51
+ # Tell if authentication through request.params is enabled. True by default.
52
+ # It can be set to an array that will enable params authentication only for the
53
+ # given strategies, for example, `config.params_authenticatable = [:database]` will
54
+ # enable it only for database (email + password) authentication.
55
+ # config.params_authenticatable = true
56
+
57
+ # Tell if authentication through HTTP Auth is enabled. False by default.
58
+ # It can be set to an array that will enable http authentication only for the
59
+ # given strategies, for example, `config.http_authenticatable = [:database]` will
60
+ # enable it only for database authentication. The supported strategies are:
61
+ # :database = Support basic authentication with authentication key + password
62
+ # config.http_authenticatable = false
63
+
64
+ # If http headers should be returned for AJAX requests. True by default.
65
+ # config.http_authenticatable_on_xhr = true
66
+
67
+ # The realm used in Http Basic Authentication. 'Application' by default.
68
+ # config.http_authentication_realm = 'Application'
69
+
70
+ # It will change confirmation, password recovery and other workflows
71
+ # to behave the same regardless if the e-mail provided was right or wrong.
72
+ # Does not affect registerable.
73
+ # config.paranoid = true
74
+
75
+ # By default Devise will store the user in session. You can skip storage for
76
+ # particular strategies by setting this option.
77
+ # Notice that if you are skipping storage for all authentication paths, you
78
+ # may want to disable generating routes to Devise's sessions controller by
79
+ # passing skip: :sessions to `devise_for` in your config/routes.rb
80
+ config.skip_session_storage = [:http_auth]
81
+
82
+ # By default, Devise cleans up the CSRF token on authentication to
83
+ # avoid CSRF token fixation attacks. This means that, when using AJAX
84
+ # requests for sign in and sign up, you need to get a new CSRF token
85
+ # from the server. You can disable this option at your own risk.
86
+ # config.clean_up_csrf_token_on_authentication = true
87
+
88
+ # ==> Configuration for :database_authenticatable
89
+ # For bcrypt, this is the cost for hashing the password and defaults to 10. If
90
+ # using other encryptors, it sets how many times you want the password re-encrypted.
91
+ #
92
+ # Limiting the stretches to just one in testing will increase the performance of
93
+ # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
94
+ # a value less than 10 in other environments. Note that, for bcrypt (the default
95
+ # encryptor), the cost increases exponentially with the number of stretches (e.g.
96
+ # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation).
97
+ config.stretches = Rails.env.test? ? 1 : 10
98
+
99
+ # Setup a pepper to generate the encrypted password.
100
+ # config.pepper = '8ff086600aff82d68ff1e00d23c99c821e66652ec8c2a5b48f58de4a56b325cb532f6db660cf58fc5ecb473b9d851be8cd1badff0a1053bc9dc045f78b6e6772'
101
+
102
+ # ==> Configuration for :confirmable
103
+ # A period that the user is allowed to access the website even without
104
+ # confirming their account. For instance, if set to 2.days, the user will be
105
+ # able to access the website for two days without confirming their account,
106
+ # access will be blocked just in the third day. Default is 0.days, meaning
107
+ # the user cannot access the website without confirming their account.
108
+ # config.allow_unconfirmed_access_for = 2.days
109
+
110
+ # A period that the user is allowed to confirm their account before their
111
+ # token becomes invalid. For example, if set to 3.days, the user can confirm
112
+ # their account within 3 days after the mail was sent, but on the fourth day
113
+ # their account can't be confirmed with the token any more.
114
+ # Default is nil, meaning there is no restriction on how long a user can take
115
+ # before confirming their account.
116
+ # config.confirm_within = 3.days
117
+
118
+ # If true, requires any email changes to be confirmed (exactly the same way as
119
+ # initial account confirmation) to be applied. Requires additional unconfirmed_email
120
+ # db field (see migrations). Until confirmed, new email is stored in
121
+ # unconfirmed_email column, and copied to email column on successful confirmation.
122
+ config.reconfirmable = true
123
+
124
+ # Defines which key will be used when confirming an account
125
+ # config.confirmation_keys = [ :email ]
126
+
127
+ # ==> Configuration for :rememberable
128
+ # The time the user will be remembered without asking for credentials again.
129
+ # config.remember_for = 2.weeks
130
+
131
+ # If true, extends the user's remember period when remembered via cookie.
132
+ # config.extend_remember_period = false
133
+
134
+ # Options to be passed to the created cookie. For instance, you can set
135
+ # secure: true in order to force SSL only cookies.
136
+ # config.rememberable_options = {}
137
+
138
+ # ==> Configuration for :validatable
139
+ # Range for password length.
140
+ config.password_length = 8..128
141
+
142
+ # Email regex used to validate email formats. It simply asserts that
143
+ # one (and only one) @ exists in the given string. This is mainly
144
+ # to give user feedback and not to assert the e-mail validity.
145
+ # config.email_regexp = /\A[^@]+@[^@]+\z/
146
+
147
+ # ==> Configuration for :timeoutable
148
+ # The time you want to timeout the user session without activity. After this
149
+ # time the user will be asked for credentials again. Default is 30 minutes.
150
+ # config.timeout_in = 30.minutes
151
+
152
+ # If true, expires auth token on session timeout.
153
+ # config.expire_auth_token_on_timeout = false
154
+
155
+ # ==> Configuration for :lockable
156
+ # Defines which strategy will be used to lock an account.
157
+ # :failed_attempts = Locks an account after a number of failed attempts to sign in.
158
+ # :none = No lock strategy. You should handle locking by yourself.
159
+ # config.lock_strategy = :failed_attempts
160
+
161
+ # Defines which key will be used when locking and unlocking an account
162
+ # config.unlock_keys = [ :email ]
163
+
164
+ # Defines which strategy will be used to unlock an account.
165
+ # :email = Sends an unlock link to the user email
166
+ # :time = Re-enables login after a certain amount of time (see :unlock_in below)
167
+ # :both = Enables both strategies
168
+ # :none = No unlock strategy. You should handle unlocking by yourself.
169
+ # config.unlock_strategy = :both
170
+
171
+ # Number of authentication tries before locking an account if lock_strategy
172
+ # is failed attempts.
173
+ # config.maximum_attempts = 20
174
+
175
+ # Time interval to unlock the account if :time is enabled as unlock_strategy.
176
+ # config.unlock_in = 1.hour
177
+
178
+ # Warn on the last attempt before the account is locked.
179
+ # config.last_attempt_warning = false
180
+
181
+ # ==> Configuration for :recoverable
182
+ #
183
+ # Defines which key will be used when recovering the password for an account
184
+ # config.reset_password_keys = [ :email ]
185
+
186
+ # Time interval you can reset your password with a reset password key.
187
+ # Don't put a too small interval or your users won't have the time to
188
+ # change their passwords.
189
+ config.reset_password_within = 6.hours
190
+
191
+ # The default HTTP method used to sign out a resource. Default is :delete.
192
+ config.sign_out_via = :delete
193
+
194
+ # don't serialize tokens
195
+ Devise::Models::Authenticatable::BLACKLIST_FOR_SERIALIZATION << :tokens
196
+
197
+ # mounted routes will point to this
198
+ Rails.application.config.after_initialize do
199
+ if defined?(::OmniAuth)
200
+ ::OmniAuth::config.path_prefix = config.omniauth_path_prefix = DeviseTokenAuth.omniauth_prefix
201
+ end
202
+ end
203
+
204
+ config.warden do |manager|
205
+ manager.failure_app = TokenAuthFailureApp
206
+ end
207
+ end