Gitlab OpenID Connect integration fails with certificate verify failed - gitlab-omnibus

I'm trying to integrate Gitlab (deployed from docker image gitlab/gitlab-ce) with our internal OpenID provider and getting error 500 and the following message in logs when trying to authenticate
OpenIDConnect::Discovery::DiscoveryFailed (SSL_connect returned=1 errno=0 state=error: certificate verify failed (unable to get local issuer certificate)):
lib/gitlab/middleware/rails_queue_duration.rb:27:in `call'
lib/gitlab/metrics/rack_middleware.rb:17:in `block in call'
lib/gitlab/metrics/transaction.rb:57:in `run'
lib/gitlab/metrics/rack_middleware.rb:17:in `call'
lib/gitlab/middleware/multipart.rb:103:in `call'
lib/gitlab/request_profiler/middleware.rb:16:in `call'
lib/gitlab/middleware/go.rb:20:in `call'
lib/gitlab/etag_caching/middleware.rb:13:in `call'
lib/gitlab/middleware/correlation_id.rb:16:in `block in call'
lib/gitlab/middleware/correlation_id.rb:15:in `call'
lib/gitlab/middleware/read_only/controller.rb:40:in `call'
lib/gitlab/middleware/read_only.rb:18:in `call'
lib/gitlab/middleware/basic_health_check.rb:25:in `call'
lib/gitlab/request_context.rb:26:in `call'
lib/gitlab/metrics/requests_rack_middleware.rb:29:in `call'
lib/gitlab/middleware/release_env.rb:12:in `call'
Our OpenID provider uses TLS certs signed by internal CA. I installed the CA certs using standard Debian update-ca-certificates in the Gitlab container and also put them in /etc/gitlab/trusted-certs and reconfigured/restarted everything, without success.
I have gitlab.rb set up for OIDC according to this doku.

Updated my config in line with a different example
gitlab_rails['omniauth_providers'] = [
{
'name' => 'oauth2_generic',
'label' => 'IDP',
'app_id' => 'my-app-id',
'app_secret' => 'xxx',
'args' => {
client_options: {
'site' => 'https://idp.example.com/auth/realms/example.com/protocol/openid-connect/',
'authorize_url' => 'auth',
'user_info_url' => 'userinfo',
'token_url' => 'token'
},
user_response_structure: {
id_path: 'preferred_username',
attributes: { nickname: 'preferred_username' }
},
name: 'oauth2_generic',
strategy_class: 'OmniAuth::Strategies::OAuth2Generic'
},
}
]
and it works!
But no idea why any of the changes should be related to certificate validation :(

Related

opensearch-ruby error on verifying ssl certificate: certificate verify failed (Hostname mismatch) (Faraday::SSLError)

I have a simple script and I am trying to perform using the opensearch-ruby client a simple search on my index. If I try to perform the query with ssl verification, my request succeeds. However, I am not able to perform the query if I enforce ssl verification. My request is failing saying that the certificate verify failed (Hostname mismatch). Below you can have a look on my script and the stacktrace after trying to execute my script.
Note that when I generate my certificate I use as CN=my.host.com
Do I miss something in my configuration when I am creating my client?
client = OpenSearch::Client.new(host: 'my.host.com',
port: 9200,
user: 'admin',
password: 'mypassword',
scheme: 'https',
transport_options: { ssl: {
verify: true,
ca_file: '/certs/root-ca.pem' } })
index_name = "my-index"
term = "Joe D"
query = {
'multi_match': {
'query': term,
'fields': ['name']
}
}
response = client.search(
body: query,
index: index_name
)
puts JSON.pretty_generate(response)
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/net-protocol-0.1.2/lib/net/protocol.rb:46:in `connect_nonblock': SSL_connect returned=1 errno=0 state=error: certificate verify failed (Hostname mismatch) (Faraday::SSLError)
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/net-protocol-0.1.2/lib/net/protocol.rb:46:in `ssl_socket_connect'
from C:/Ruby30-x64/lib/ruby/3.0.0/net/http.rb:1038:in `connect'
from C:/Ruby30-x64/lib/ruby/3.0.0/net/http.rb:970:in `do_start'
from C:/Ruby30-x64/lib/ruby/3.0.0/net/http.rb:965:in `start'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/net-http-persistent-4.0.1/lib/net/http/persistent.rb:655:in `start'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/net-http-persistent-4.0.1/lib/net/http/persistent.rb:595:in `connection_for'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/net-http-persistent-4.0.1/lib/net/http/persistent.rb:885:in `request'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/faraday-net_http_persistent-1.2.0/lib/faraday/adapter/net_http_persistent.rb:71:in `perform_request'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/faraday-net_http-1.0.1/lib/faraday/adapter/net_http.rb:66:in `block in call'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/faraday-1.10.0/lib/faraday/adapter.rb:50:in `connection'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/faraday-net_http-1.0.1/lib/faraday/adapter/net_http.rb:64:in `call'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/faraday-1.10.0/lib/faraday/rack_builder.rb:154:in `build_response'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/faraday-1.10.0/lib/faraday/connection.rb:516:in `run_request'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/opensearch-transport-2.0.0/lib/opensearch/transport/transport/http/faraday.rb:56:in `block in perform_request'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/opensearch-transport-2.0.0/lib/opensearch/transport/transport/base.rb:297:in `perform_request'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/opensearch-transport-2.0.0/lib/opensearch/transport/transport/http/faraday.rb:45:in `perform_request'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/opensearch-transport-2.0.0/lib/opensearch/transport/client.rb:193:in `perform_request'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/opensearch-ruby-2.0.2/lib/opensearch.rb:92:in `open_search_validation_request'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/opensearch-ruby-2.0.2/lib/opensearch.rb:58:in `verify_open_search'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/opensearch-ruby-2.0.2/lib/opensearch.rb:47:in `method_missing'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/opensearch-api-2.0.2/lib/opensearch/api/actions/search.rb:106:in `search'
from C:/Users/vasgat/RubymineProjects/OpenSearchTest/myclient.rb:68:in `<main>'

SSL_connect returned=1 errno=0 state=unknown state: unknown protocol

After reading through many posts I couldn't find a solution to my problem. I've made a test connection with www.smtper.net which was successful. My error.log only tells me the error:
OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=unknown state: unknown protocol
app/controllers/passwords_controller.rb:11:in `create'
Maybe it has something to do with my nginx settings?
Issue
I'm trying to configure my smtp via mailgun (or gmail) but without success.
My configuration in developement.rb looks like:
config.action_mailer.default_url_options = { :host => "xxxxx:8765" }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "mail.google.com",
:user_name => "xxx#gmail.com",
:password => "xxxxxx",
:authentication => :plain,
:enable_starttls_auto => true
}
And the error is thrown at the action create, line 11:
AccountMailer.password_reset_email(#account).deliver
I have installed OpenSSL 1.0.1f on my development server
TRACE
/root/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/protocol.rb:44:in `connect_nonblock'
/root/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/protocol.rb:44:in `ssl_socket_connect'
/root/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/smtp.rb:584:in `tlsconnect'
/root/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/smtp.rb:552:in `do_start'
/root/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/smtp.rb:518:in `start'
mail (2.7.0) lib/mail/network/delivery_methods/smtp.rb:109:in `start_smtp_session'
mail (2.7.0) lib/mail/network/delivery_methods/smtp.rb:100:in `deliver!'
mail (2.7.0) lib/mail/message.rb:2160:in `do_delivery'
mail (2.7.0) lib/mail/message.rb:260:in `block in deliver'
actionmailer (4.2.8) lib/action_mailer/base.rb:543:in `block in deliver_mail'
activesupport (4.2.8) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.8) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.8) lib/active_support/notifications.rb:164:in `instrument'
actionmailer (4.2.8) lib/action_mailer/base.rb:541:in `deliver_mail'
mail (2.7.0) lib/mail/message.rb:260:in `deliver'
actionmailer (4.2.8) lib/action_mailer/message_delivery.rb:85:in `deliver_now'
actionmailer (4.2.8) lib/action_mailer/message_delivery.rb:105:in `deliver'
app/controllers/passwords_controller.rb:11:in `create'
What happens if you try this settings and get rid of everything else you currently have:
# /config/environments/development.rb
# Gmail configuration
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'example.com',
user_name: ENV['EMAIL_USER'],
password: ENV['EMAIL_PASS'],
authentication: 'plain',
enable_starttls_auto: true
}
I'm not sure you need to monkey with smtper.net but perhaps see this, even though it's very old, it probably should still work:
http://blog.napcs.com/2013/07/21/rails_ssl_simple_wa/
You'll need to set those environment variables as you obviously should never want to commit credentials in your git repo.
But also see these posts as you may need to do some other things for gmail
(Ruby) Getting Net::SMTP working with Gmail...?
Rails 4, how to correctly configure smtp settings (gmail)

Error TypeError: can't dup NilClass - Stripe

I am getting an error ERROR TypeError: can't dup NilClass when processing a Strip charge. I have followed the rails stripe integration documentation.
The error from the terminal is:
Started POST "/charges" for ::1 at 2016-05-27 12:35:48 +0100
Processing by ChargesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"URydkbi6DghMZnzVqbf79KU+YRy/T+9g3UQ8tO8HTXG4uqvEMzdm6V/EjseNiZiIPS3ziOJJTpJ1K+gGMipksg==", "stripeToken"=>"tok_18FjA2JxArkI2Z35Q4MB3sCE", "stripeTokenType"=>"card", "stripeEmail"=>"fergusmorton#live.com"}
[2016-05-27 12:35:48] ERROR TypeError: can't dup NilClass
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httprequest.rb:392:in `dup'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httprequest.rb:392:in `meta_vars'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/handler/webrick.rb:59:in `service'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
Completed 500 Internal Server Error in 55ms (ActiveRecord: 0.0ms)
Net::HTTPFatalError (500 "Internal Server Error "):
app/controllers/charges_controller.rb:9:in `create'
Net::HTTPFatalError: 500 "Internal Server Error "
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/net/http/response.rb:119:in `error!'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/net/http/response.rb:128:in `value'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/net/http.rb:915:in `connect'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/net/http.rb:863:in `do_start'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/net/http.rb:852:in `start'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rest-client-1.8.0-x86-mingw32/lib/restclient/request.rb:413:in `transmit'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rest-client-1.8.0-x86-mingw32/lib/restclient/request.rb:176:in `execute'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rest-client-1.8.0-x86-mingw32/lib/restclient/request.rb:41:in `execute'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/stripe-1.43.0/lib/stripe.rb:298:in `execute_request'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/stripe-1.43.0/lib/stripe.rb:196:in `execute_request_with_rescues'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/stripe-1.43.0/lib/stripe.rb:148:in `request'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/stripe-1.43.0/lib/stripe/api_operations/request.rb:15:in `request'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/stripe-1.43.0/lib/stripe/api_operations/create.rb:5:in `create'
from C:/Users/Fergus/best-ever-me-v-1.1/app/controllers/charges_controller.rb:9:in `create'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/abstract_controller/base.rb:198:in `process_action'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal/rendering.rb:10:in `process_action'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:117:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:117:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:505:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:505:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:92:in `__run_callbacks__'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:778:in `_run_process_action_callbacks'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:81:in `run_callbacks'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/abstract_controller/callbacks.rb:19:in `process_action'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal/rescue.rb:29:in `process_action'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/notifications.rb:164:in `block in instrument'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/notifications.rb:164:in `instrument'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/abstract_controller/base.rb:137:in `process'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionview-4.2.5/lib/action_view/rendering.rb:30:in `process'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal.rb:196:in `dispatch'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal.rb:237:in `block in action'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/routing/route_set.rb:76:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/routing/route_set.rb:76:in `dispatch'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/routing/route_set.rb:45:in `serve'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/journey/router.rb:43:in `block in serve'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/journey/router.rb:30:in `each'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/journey/router.rb:30:in `serve'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/routing/route_set.rb:817:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/etag.rb:24:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/conditionalget.rb:38:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/head.rb:13:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/flash.rb:260:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:225:in `context'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:220:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/cookies.rb:560:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/query_cache.rb:36:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:377:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:88:in `__run_callbacks__'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:81:in `run_callbacks'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/reloader.rb:73:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/web-console-2.3.0/lib/web_console/middleware.rb:28:in `block in call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/web-console-2.3.0/lib/web_console/middleware.rb:18:in `catch'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/web-console-2.3.0/lib/web_console/middleware.rb:18:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/rack/logger.rb:38:in `call_app'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/rack/logger.rb:20:in `block in call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/tagged_logging.rb:68:in `block in tagged'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/tagged_logging.rb:26:in `tagged'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/tagged_logging.rb:68:in `tagged'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/rack/logger.rb:20:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/request_id.rb:21:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/methodoverride.rb:22:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/runtime.rb:18:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/lock.rb:17:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/static.rb:116:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/sendfile.rb:113:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/engine.rb:518:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/application.rb:165:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/lock.rb:17:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/content_length.rb:15:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/handler/webrick.rb:88:in `service'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
charges_controller.rb
class ChargesController < ApplicationController
def new
end
def create
# Amount in cents
#amount = 500
customer = Stripe::Customer.create(
:email => params[:stripeEmail],
:source => params[:stripeToken]
)
charge = Stripe::Charge.create(
:customer => customer.id,
:amount => #amount,
:description => 'Rails Stripe customer',
:currency => 'usd'
)
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to new_charge_path
end
end
initiliazers/stripe.rb
Rails.configuration.stripe = {
:publishable_key => ENV['PUBLISHABLE_KEY'],
:secret_key => ENV['SECRET_KEY']
}
Stripe.api_key = Rails.configuration.stripe[:secret_key]
cart/show.html.erb
<div class="shopping-cart" style="margin-top:160px;">
<%= render "shopping_cart" %>
<%= form_tag charges_path do %>
<article>
<% if flash[:error].present? %>
<div id="error_explanation">
<p><%= flash[:error] %></p>
</div>
<% end %>
<label class="amount">
<span>Amount: €<%= current_order.subtotal %> </span>
</label>
</article>
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="<%= Rails.configuration.stripe[:publishable_key] %>"
data-description="Cart Total"
data-amount="<%= current_order.subtotal %>"
data-locale="auto"></script>
<% end %>
</div>
Updated log Following Michael's Suggestions.
Started POST "/charges" for ::1 at 2016-05-31 11:45:45 +0100
Processing by ChargesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"qXPL5OhG1UA+Ui4uyB7+80/UGDGXFPnOevOf/kmZhitA1f2xY8u9oS3w3DzsIJ2P18eKpcoSWDzSnEtMlLSv6A==", "stripeToken"=>"tok_18HANXJxArkI2Z35encjc3uW", "stripeTokenType"=>"card", "stripeEmail"=>"fergusmorton#live.com"}
Unpermitted parameters: utf8, authenticity_token, stripeTokenType
Completed 500 Internal Server Error in 6ms (ActiveRecord: 0.0ms)
NoMethodError (undefined method `stripe_customer_id' for nil:NilClass):
app/controllers/charges_controller.rb:15:in `create'
NoMethodError: undefined method `stripe_customer_id' for nil:NilClass
From the code that you've shown, it looks like you may have a couple of issues, but there may be additional issues related to setup for Stripe Payment.
The process for setting up Stripe within your application is covered here.
Setup Stripe in your Application
Add Stripe keys to your config/secrets.yml file:
development:
stripe_private_key: <%= ENV["STRIPE_PRIVATE_KEY"] %>
stripe_public_key: <%= ENV["STRIPE_PUBLIC_KEY"] %>
You can keep the STRIPE_PRIVATE_KEY and STRIPE_PUBLIC_KEY in your environment. Test and production environments would require similar configuration settings.
Make certain to add this code to your controller, or in any code that you intend to use the Stripe API:
require "stripe"
Stripe.api_key = Rails.application.secrets.stripe_private_key
Add a Migration to Add Stripe Customer ID to Customer
This migration provides an example based on a User class; your application may use a different model, so adjust as necessary to fit your purpose.
class AddUserStripeCustomerId < ActiveRecord::Migration
def change
change_table :users do |t|
t.string :stripe_customer_id, limit: 50, null: true
end
end
end
Create a Customer
When you're ready to begin the billing process for a customer, create the customer:
if !#user.stripe_customer_id
customer = Stripe::Customer.create(
:email => stripe_details[:stripeEmail],
:source => stripe_details[:stripeToken]
)
User.update(stripe_customer_id: customer)
end
Make sure to save the customer ID in your User model. You'll need to take care to not re-create and overwrite your customer ID for a user, because this is your tie-in to the Stripe payments system for that user.
Implement the Controller
The form elements (parameters) that you're submitting aren't scoped like a Rails model-based form. Typically, this is due to using a form_tag for a form that's not based directly on a model. This means that instead of having parameters scoped by a model hash, the parameters are unscoped.
Your strong parameters aren't included here, but they may be part of the issue. Make sure that you have the stripeToken and stripeEmail included in the permit list, like so:
params.permit(:stripeToken, :stripeCard, :stripeEmail)
Make certain to not include the typical require method on the strong parameters, as that validates that the parameters are scoped by a model object. In your create method, you should call the strong parameters method, and use the result, like so:
require "stripe"
class ChargesController < ApplicationController
Stripe.api_key = Rails.application.secrets.stripe_private_key
def new
end
def create
# Amount in cents
#amount = 500
stripe_details = stripe_params
if !#user.stripe_customer_id
customer = Stripe::Customer.create(
:email => stripe_details[:stripeEmail],
:source => stripe_details[:stripeToken]
)
User.update(stripe_customer_id: customer)
end
charge = Stripe::Charge.create(
:customer => customer.id,
:amount => #amount,
:description => 'Rails Stripe customer',
:currency => 'usd'
)
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to new_charge_path
end
private
def stripe_params
params.permit(:stripeToken, :stripeCard, :stripeEmail)
end
end
More Information
Also check out How to create a charge and a customer in Stripe (Rails) for additional details on managing customer accounts and charges with Stripe.

ruby oauth2 put request returns invalid block type error

I'm able to perform get and post requests fine, but when I try to do a put request with the same format, I get:
Zlib::DataError (invalid block type)
here is the backtrace
/Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http/response.rb:357:in `finish': invalid block type (Zlib::DataError)
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http/response.rb:357:in `finish'
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http/response.rb:262:in `ensure in inflater'
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http/response.rb:262:in `inflater'
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http/response.rb:274:in `read_body_0'
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http/response.rb:201:in `read_body'
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http/response.rb:226:in `body'
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http/response.rb:163:in `reading_body'
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http.rb:1412:in `block in transport_request'
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http.rb:1403:in `catch'
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http.rb:1403:in `transport_request'
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http.rb:1376:in `request'
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http.rb:1369:in `block in request'
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http.rb:852:in `start'
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http.rb:1367:in `request'
from /Users/psi/.rvm/gems/ruby-2.0.0-p451/gems/faraday-0.9.0/lib/faraday/adapter/net_http.rb:80:in `perform_request'
from /Users/psi/.rvm/gems/ruby-2.0.0-p451/gems/faraday-0.9.0/lib/faraday/adapter/net_http.rb:39:in `call'
from /Users/psi/.rvm/gems/ruby-2.0.0-p451/gems/faraday-0.9.0/lib/faraday/request/url_encoded.rb:15:in `call'
from /Users/psi/.rvm/gems/ruby-2.0.0-p451/gems/faraday-0.9.0/lib/faraday/rack_builder.rb:139:in `build_response'
from /Users/psi/.rvm/gems/ruby-2.0.0-p451/gems/faraday-0.9.0/lib/faraday/connection.rb:377:in `run_request'
from /Users/psi/.rvm/gems/ruby-2.0.0-p451/gems/oauth2-0.9.3/lib/oauth2/client.rb:90:in `request'
from /Users/psi/.rvm/gems/ruby-2.0.0-p451/gems/oauth2-0.9.3/lib/oauth2/access_token.rb:107:in `request'
from /Users/psi/.rvm/gems/ruby-2.0.0-p451/gems/oauth2-0.9.3/lib/oauth2/access_token.rb:128:in `put'
from api_check.rb:50:in `<main>'
here is the setup code
require 'oauth2'
client = OAuth2::Client.new(CLIENTID, CLIENTSECRET,
site: SITE, token_url: TOKENURL)
token = client.client_credentials.get_token
response = token.put(PATH, {body: {params1: PARAM1}})
Im using oauth2 version 0.9.3
If there is something wrong with the way I'm doing a request, I have no indication from the error log.
If more info is needed let me know.
If I use a different Faraday adapter like EventMachine, I get the correct OAuth2::Error exception with a detailed message instead of just breaking.
To change the adapter, add the desired adapter to the Gemfile and add this line before calling OAuth2 methods
Faraday.default_adapter = :em_http

Mongomapper and Sinatra undefined method `update_attributes' for nil:NilClass

I getting the error "undefined method `update_attributes' for nil:NilClass" when using Sinatra with MongoMapper.
Model:
class Publication
include MongoMapper::Document
key :page, String
key :title, String
key :body, String
end
and code where i getting error:
post '/edit' do
#article = Publication.update({:page => 'main'}, {$set => {:title => params[:title], :body => params[:body]}})
end
i'm tried to make update in mongo console and it was successfully updated:
> db.publications.update({page: 'main'},{$set: {body: '333', title: '111'}})
> db.publications.find({page: 'main'})
{ "_id" : ObjectId("4fa45046530a6978e3000003"), "body" : "333", "page" : "main", "title" : "111" }
Full stack trace:
[2012-05-06 03:04:22] INFO WEBrick 1.3.1
[2012-05-06 03:04:22] INFO ruby 1.8.7 (2010-01-10) [universal-darwin11.0]
== Sinatra/1.3.2 has taken the stage on 4567 for development with backup from WEBrick
[2012-05-06 03:04:23] INFO WEBrick::HTTPServer#start: pid=32266 port=4567
localhost - - [06/May/2012:03:04:27 MSK] "GET /edit HTTP/1.1" 200 193
- -> /edit
localhost - - [06/May/2012:03:04:27 MSK] "GET /favicon.ico HTTP/1.1" 404 447
- -> /favicon.ico
NoMethodError - undefined method `update_attributes' for nil:NilClass:
/Library/Ruby/Gems/1.8/gems/mongo_mapper- 0.11.1/lib/mongo_mapper/plugins/querying.rb:118:in `update_single'
/Library/Ruby/Gems/1.8/gems/mongo_mapper-0.11.1/lib/mongo_mapper/plugins/querying.rb:117:in `tap'
/Library/Ruby/Gems/1.8/gems/mongo_mapper-0.11.1/lib/mongo_mapper/plugins/querying.rb:117:in `update_single'
/Library/Ruby/Gems/1.8/gems/mongo_mapper-0.11.1/lib/mongo_mapper/plugins/querying.rb:45:in `update'
main.rb:48:in `POST /edit'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:1211:in `call'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:1211:in `compile!'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:785:in `[]'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:785:in `route!'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:801:in `route_eval'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:785:in `route!'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:822:in `process_route'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:820:in `catch'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:820:in `process_route'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:784:in `route!'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:783:in `each'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:783:in `route!'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:886:in `dispatch!'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:719:in `call!'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:871:in `invoke'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:871:in `catch'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:871:in `invoke'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:719:in `call!'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:705:in `call'
/Library/Ruby/Gems/1.8/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `call'
/Library/Ruby/Gems/1.8/gems/rack-protection-1.2.0/lib/rack/protection/path_traversal.rb:16:in `call'
/Library/Ruby/Gems/1.8/gems/rack-protection-1.2.0/lib/rack/protection/json_csrf.rb:17:in `call'
/Library/Ruby/Gems/1.8/gems/rack-protection-1.2.0/lib/rack/protection/base.rb:47:in `call'
/Library/Ruby/Gems/1.8/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `call'
/Library/Ruby/Gems/1.8/gems/rack-1.4.1/lib/rack/logger.rb:15:in `call'
/Library/Ruby/Gems/1.8/gems/rack-1.4.1/lib/rack/head.rb:9:in `call'
/Library/Ruby/Gems/1.8/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.2/lib/sinatra/showexceptions.rb:21:in `call'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:1334:in `call'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:1416:in `synchronize'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:1334:in `call'
/Library/Ruby/Gems/1.8/gems/rack-1.4.1/lib/rack/handler/webrick.rb:59:in `service'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
/Library/Ruby/Gems/1.8/gems/rack-1.4.1/lib/rack/handler/webrick.rb:13:in `run'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.2/lib/sinatra/base.rb:1295:in `run!'
/Library/Ruby/Gems/1.8/gems/sinatra-1.3.2/lib/sinatra/main.rb:25
main.rb:53
anyone can say for what reason I do not get properly updated in the ruby code?
You probably meant to have :$set instead of $set as your key:
#article = Publication.update({:page => 'main'}, {:$set => {:title => params[:title], :body => params[:body]}})
What you have is using the global variable $set for the key, which is nil (since all global variables default to nil). For example:
{ $set => "something" } #=> {nil=>"something"}
{ :$set => "something" } #=> {:$set=>"something"}

Resources