omniauth and google with sinatra on heroku - ruby

I'm trying to use OmniAuth in a sinatra app with google as the login provider. Using the twitter and facebook providers work fine:
require 'omniauth'
require 'openid'
require 'openid/store/filesystem'
use OmniAuth::Builder do
use OmniAuth::Strategies::OpenID, OpenID::Store::Filesystem.new('./tmp'), :name => 'google', :identifier => 'https://www.google.com/accounts/o8/id'
end
get '/sign_in'
redirect '/auth/google'
end
Thoughts? When the browser tries to get '/auth/google', it gets a 503 - Service Unavailable. There is nothing in the heroku logs
Thoughts or suggestions on what this might be?
I just started a bounty on this question - what I'm hoping for is a sample implementation that works on heroku.
I increased the log level on heroku. Here is what I'm getting now:
2011-07-07T16:15:09+00:00 heroku[nginx]: GET /sign_in/?p=google HTTP/1.1 | 207.224.213.179 | 269 | http | 302
2011-07-07T16:15:09+00:00 app[web.1]: I, [2011-07-07T09:15:09.863397 #1] INFO -- OpenID: Error attempting to use stored discovery information: OpenID::TypeURIMismatch
2011-07-07T16:15:09+00:00 app[web.1]: I, [2011-07-07T09:15:09.863480 #1] INFO -- OpenID: Attempting discovery to verify endpoint
2011-07-07T16:15:09+00:00 app[web.1]: I, [2011-07-07T09:15:09.863512 #1] INFO -- OpenID: Performing discovery on https://www.google.com/accounts/o8/id?id=AItOawlAKE9QAQb9mMRyYCCmAkEYIcqfmhrA080
2011-07-07T16:15:09+00:00 app[web.1]: I, [2011-07-07T09:15:09.865033 #1] INFO -- OpenID: WARNING: making https request to https://www.google.com/accounts/o8/id?id=AItOawlAKE9QAQb9mMRyYCCmAkEYIcqfmhrA080 without verifying server certificate; no CA path was specified.
2011-07-07T16:15:09+00:00 app[web.1]: 207.224.213.179 - - [07/Jul/2011 09:15:09] "POST /auth/google/callback HTTP/1.1" 302 - 0.0956
2011-07-07T16:15:09+00:00 heroku[router]: GET myurl.com/auth/google/callback dyno=web.1 queue=0 wait=0ms service=100ms status=302 bytes=0

The page at https://github.com/intridea/omniauth/wiki/OpenID-and-Google-Apps gives two possible solutions:
On Heroku you can change the path to "./tmp" or use Memcached.
It seems like you already tried the Memcached solution - do you have a Memcached instance running and properly setup on Heroku?

You could use google's openid to sign in.
use OmniAuth::Builder do
provider :openid, OpenID::Store::Filesystem.new('/tmp')
use OmniAuth::Strategies::OpenID, OpenID::Store::Filesystem.new('/tmp'), :name => 'google', :identifier => 'https://www.google.com/accounts/o8/id'
end

Related

NameError - unitilaized constant - only in production

I have a ruby on rails app that is hosted on heroku. When I try to create an item running it in "development" mode, everything works great and there are no issues. However, when I switch the app to run in "production" mode I'm getting the following.
This was a Ruby 2.2.x upgraded to 2.5.x and rails 4.1 upgraded to 5.2.
Any ideas or suggestions on why this is failing in production but works fine in development?
Started POST "/items" for 1.2.3.4 at 2020-10-19 03:22:06 +0000
2020-10-19T03:22:06.870055+00:00 app[web.1]: Processing by ItemController#create as HTML
2020-10-19T03:22:06.870358+00:00 app[web.1]: Parameters: {###Redacted##}
2020-10-19T03:22:06.926046+00:00 app[web.1]: Completed 500 Internal Server Error in 54ms (ActiveRecord: 15.8ms)
2020-10-19T03:22:06.999133+00:00 app[web.1]: I, [2020-10-19T03:22:06.998984 #11] INFO -- : Sending event 18b887c876d4524b5cd46849a98aaeb1 to Sentry
2020-10-19T03:22:07.271068+00:00 app[web.1]:
2020-10-19T03:22:07.271478+00:00 app[web.1]: NameError (uninitialized constant #<Class:0x0000567238d68165>::Slug):
2020-10-19T03:22:07.276183+00:00 app[web.1]:
2020-10-19T03:22:07.276248+00:00 app[web.1]: app/models/item.rb:305:in `name_to_slug'
2020-10-19T03:22:07.276248+00:00 app[web.1]: app/models/item.rb:293:in `generate_slug'
I tracked this back to a custom class that was located in the "lib" folder. Moving from Rails 4 to 5 it seems like some behaviors changed with loading custom classes which needed to be accounted for:
https://gist.github.com/maxivak/381f1e964923f1d469c8d39da8e2522f

Why is the bot on Heroku Server not responding?

I programmed a simple bot that is connected to Google Sheets API. It asks a few questions to the user and stores it in the Sheet I have. When I use bot.polling it works fine, but I was trying the webhook so I could use Heroku to have my bot running 24/7.
I introduced the code:
#server.route('/' + token, methods=['POST'])
def getMessage():
bot.process_new_updates([telebot.types.Update.de_json(request.stream.read().decode("utf-8"))])
return "!", 200
#server.route("/")
def webhook():
bot.remove_webhook()
bot.set_webhook(url = '<Heroku App Link>' + token)
return "!", 200
if __name__ == "__main__":
server.run(host="0.0.0.0", port = int(os.environ.get('PORT', 5000)))
I have the requirements.txt file and the Procfile that currently is like this:
web: python3 bot.py
I tried a bunch of things in the Procfile but this is the only one that didn't gave an error.
When I saw the log this is what I got:
2019-09-24T10:18:54.369238+00:00 heroku[web.1]: State changed from crashed to starting
2019-09-24T10:19:04.416777+00:00 heroku[web.1]: Starting process with command `python3 bot.py`
2019-09-24T10:19:09.868915+00:00 heroku[web.1]: State changed from starting to up
2019-09-24T10:19:09.790773+00:00 app[web.1]: * Serving Flask app "bot" (lazy loading)
2019-09-24T10:19:09.790800+00:00 app[web.1]: * Environment: production
2019-09-24T10:19:09.790853+00:00 app[web.1]: WARNING: This is a development server. Do not use it in a production deployment.
2019-09-24T10:19:09.790940+00:00 app[web.1]: Use a production WSGI server instead.
2019-09-24T10:19:09.790991+00:00 app[web.1]: * Debug mode: off
2019-09-24T10:19:09.799470+00:00 app[web.1]: * Running on http://0.0.0.0:57826/ (Press CTRL+C to quit)
2019-09-24T10:19:15.000000+00:00 app[api]: Build succeeded
Can anyone help me understand why the bot doesn't answer any commands?

Heroku PR App can't connect to GrapheneDB

I just created a new PR App in Heroku with the GrapheneDB add on.
I'm seeing the following in my logs:
2018-05-18T20:11:52.702973+00:00 app[web.1]: neo4j.exceptions.ProtocolError: Connection to ('ip', 24786) closed without handshake response
2018-05-18T20:11:52.704465+00:00 app[web.1]: 2018-05-18 20:11:52,704 INFO ~~ [CONNECT] ('ip', 24786)
2018-05-18T20:11:52.705999+00:00 app[web.1]: 2018-05-18 20:11:52,705 INFO C: [HANDSHAKE] 0x6060B017 [1, 0, 0, 0]
2018-05-18T20:11:52.707922+00:00 app[web.1]: 2018-05-18 20:11:52,707 ERROR S: [CLOSE]
2018-05-18T20:11:52.710745+00:00 app[web.1]: 2018-05-18 20:11:52,708 ERROR Connection to ('ip', 24786) closed without handshake response
So far I have:
Connected to the browser
nslookup from the console shows the same ip as the logs (I can't ping from the heroku instance)
Rotated database credentials from the GrapheneDB dashboard
Removed the add on and re-added it
Am I missing something?
Env:
Python 3.6.5
neo4j-driver 1.5.3
Driver Python Code:
from django.conf import settings
from django.utils.functional import SimpleLazyObject
from neo4j.v1 import GraphDatabase, basic_auth, TRUST_ON_FIRST_USE
def get_driver():
return GraphDatabase.driver(
settings.NEO4J_BOLT_URL,
auth=basic_auth(settings.NEO4J_USERNAME, settings.NEO4J_PASSWORD),
encrypted=False,
trust=TRUST_ON_FIRST_USE,
)
driver = SimpleLazyObject(get_driver)
Just to follow up. It turns out that TRUST_ON_FIRST_USE does not work with GrapheneDB. TRUST_ON_FIRST_USE is also now deprecated.
Removing it allowed the connection to Neo4j work.

Heroku H15 errors with Elixir/Phoenix Channels

Once I started using Channels with Phoenix, I started getting a lot of these errors on Heroku:
heroku[router]: at=error code=H15 desc="Idle connection" method=GET
path="/socket/websocket?guardian_token=eyJhbGciOiJIUz[...]&vsn=1.0.0" host=[...]
dyno=web.1 connect=0ms service=87803ms status=503 bytes=
A reliable way to reproduce this is on a laptop:
Open a Phoenix page that connects to WebSockets
Close the lid of your laptop
Wait a minute or so (WiFi to disconnect/OS goes to sleep)
The H15 error will occur.
I've set a 45s timeout on my UserChannel already; I'm running Elixir 1.4.2, Phoenix 1.2.1 and my phoenix.js was just upgraded to the one used in Phoenix 1.3.0-rc0 (link to rev)
I can see the error logged on the front-end, but after that it reconnects happily to the backend:
2017-03-04 23:28:55.351 receive: ok user:2 phx_reply (3)
2017-03-04 23:29:24.269 channel: error user:2
2017-03-04 23:29:28.713 push: user:2 phx_join (4)
2017-03-04 23:29:28.745 receive: ok user:2 phx_reply (4)
Any help or ideas how to solve this is much appreciated.
Edit: I'm familiar with Heroku's H15 error code definition so I'm looking for a fix or a workaround for getting rid of the errors (other than migrating away from Heroku, of course).
Phoenix docs recommend setting the timeout for the websocket transport to < 55 seconds:
defmodule HelloWeb.UserSocket do
use Phoenix.Socket
...
## Transports
transport :websocket, Phoenix.Transports.WebSocket,
timeout: 45_000
...
end
Their explanation is:
This ensures that any idle connections are closed by Phoenix before they reach Heroku’s 55-second timeout window.

How to read log/production.log from heroku if I run on puma web server

I am running a puma web server on heroku and wants to get the .log file to check why a record is being rollbacked. I tried using heroku run bash and tried searching for config in puma.rb, but I still don't know how..
Any suggestions?
edit: I don't want heroku logs -t as it is just showing the logs from puma output. I need the output which when you tail -f log/development.log will show, more detail.
The reason I need it is because I am having a record that rollbacks and I don't know why. It only happens in production not in development, so I have to find out why.
2015-07-28T11:01:26.688980+00:00 app[web.1]: Processing by Users::RegistrationsController#create as HTML
2015-07-28T11:01:26.689027+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"ocrYdS3Ysj8dM7A32k7ssBFndoRAJSpM+qlK5Sm2t3ROWm3pSEgAO1htfbSsc/j5FUUXZmRu0RuCp2g2tqfmPw==", "user"=>{"email"=>"ml#llmmllmm.com", "password"=>"[FILTERED]"}, "commit"=>"註冊"}
2015-07-28T11:01:26.812795+00:00 app[web.1]: Identity Load (1.9ms) SELECT "identities".* FROM "identities" WHERE "identities"."email" = $1 ORDER BY "identities"."id" ASC LIMIT 1 [["email", "ml#llmmllmm.com"]]
2015-07-28T11:01:26.825136+00:00 app[web.1]: User Exists (2.3ms) SELECT 1 AS one FROM "users" WHERE "users"."referral_code" IS NULL LIMIT 1
2015-07-28T11:01:27.443614+00:00 heroku[router]: at=info method=POST path="/signup" host=new.carshare.hk request_id=c19ac7d2-7805-4c0e-b972-532264656737 fwd="220.241.70.37" dyno=web.1 connect=1ms service=766ms status=200 bytes=15584
2015-07-28T11:01:27.391858+00:00 app[web.1]: FormUser Exists (13.0ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = 'ml#llmmllmm.com' LIMIT 1
2015-07-28T11:01:27.423934+00:00 app[web.1]: Rendered svgs/_carshare_typeface_blue.html (0.6ms)
2015-07-28T11:01:27.426946+00:00 app[web.1]: Rendered shared/_flash.html.slim (0.1ms)
2015-07-28T11:01:27.398227+00:00 app[web.1]: (1.9ms) ROLLBACK
You can tail Heroku logs: heroku logs -t -a app-name
https://devcenter.heroku.com/articles/logging
Also you can try out some addons on Heroku which will provide you with a in-browser view of your logs and allow some filtering on top of it - https://addons.heroku.com/?q=log

Resources