noticed gem with slack testing - ruby-on-rails

i'm using noticed gem with have connected this with database and with email ,this is working fine
deliver_by :slack, debug: true
Notification Load (7.4ms) SELECT "notifications".* FROM "notifications" WHERE "notifications"."id" = $1 LIMIT $2 [["id", 50], ["LIMIT", 1]]
[ActiveJob] [Noticed::DeliveryMethods::Slack] [8f3f8423-81e7-4d46-86bc-
edafda6cd3e8] Performing Noticed::DeliveryMethods::Slack (Job ID: 8f3f8423-81e7-
4d46-86bc-edafda6cd3e8) from Async(default) enqueued at 2022-10-19T07:41:34Z with
arguments: {:notification_class=>"Commentnotification", :options=>{:debug=>true},
:params=>{:comment=>#<GlobalID:0x00007fcce701d0e0 #uri=#<URI::GID gid://fyp-ed-
bolt/Comment/20>>, :inquest=>#<GlobalID:0x00007fcce0c7b910 #uri=#<URI::GID
gid://fyp-ed-bolt/Inquest/1>>}, :recipient=>#<GlobalID:0x00007fcce70160d8 #uri=#.
<URI::GID gid://fyp-ed-bolt/User/1>>, :record=>#<GlobalID:0x00007fcce4fea7f0 #uri=#.
<URI::GID gid://fyp-ed-bolt/Notification/50>>}
[ActiveJob] [Noticed::DeliveryMethods::Slack] [8f3f8423-81e7-4d46-86bc-edafda6cd3e8]
Error performing Noticed::DeliveryMethods::Slack (Job ID: 8f3f8423-81e7-4d46-86bc-
edafda6cd3e8) from Async(default) in 265.87ms: NoMethodError (undefined method
`[]' for
nil:NilClass):
but getting this error while connecting with slack.

Related

I have Segmentation fault when I made insert/update blob in postgres and Ruby

I have an odd issue with a Ruby system.
Im working over Windows, I have installed rails 7.0.3 and using Postgres 13.
Im developing a simple blog and all is fine until I add an image with Active Storage.
I can notice that ONLY when is executed an update/insert into blob table (active_storage_blobs) the server crashes with "Segmentation fault".
This is the console error trace:
Started GET "/rails/active_storage/disk/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdDVG9JYTJWNVNTSWhiVGgzWTJock5IWjVOR1l6YVdKdmJtTnZhR1l6TTIxa2IySnFjQVk2QmtWVU9oQmthWE53YjNOcGRHbHZia2tpWTJsdWJHbHVaVHNnWm1sc1pXNWhiV1U5SW5Cc1lYUnBiR3h2TFdGbWFXeHBZWEl0Wlcxd2NtVnpZUzV3Ym1jaU95Qm1hV3hsYm1GdFpTbzlWVlJHTFRnbkozQnNZWFJwYkd4dkxXRm1hV3hwWVhJdFpXMXdjbVZ6WVM1d2JtY0dPd1pVT2hGamIyNTBaVzUwWDNSNWNHVkpJZzVwYldGblpTOXdibWNHT3daVU9oRnpaWEoyYVdObFgyNWhiV1U2Q214dlkyRnMiLCJleHAiOiIyMDIyLTA1LTIzVDE3OjIwOjEyLjQwMVoiLCJwdXIiOiJibG9iX2tleSJ9fQ==--56b519b58ccd4203a56c7c87d605a4a69153fa20/platillo-afiliar-empresa.png" for 127.0.0.1 at 2022-05-23 12:15:12 -0500
[ActiveJob] [ActiveStorage::AnalyzeJob] [37f30828-ff52-4c65-9144-be30425a7700] ActiveStorage::Blob Load (0.3ms) SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = $1 LIMIT $2 [["id", 42], ["LIMIT", 1]]
[ActiveJob] [ActiveStorage::AnalyzeJob] [37f30828-ff52-4c65-9144-be30425a7700] Performing ActiveStorage::AnalyzeJob (Job ID: 37f30828-ff52-4c65-9144-be30425a7700) from Async(default) enqueued at 2022-05-23T17:15:12Z with arguments: #<GlobalID:0x0000029e8ce86d40 #uri=#<URI::GID gid://dummy/ActiveStorage::Blob/42>>
[ActiveJob] [ActiveStorage::AnalyzeJob] [37f30828-ff52-4c65-9144-be30425a7700] Disk Storage (4.2ms) Downloaded file from key: m8wchk4vy4f3iboncohf33mdobjp
Processing by ActiveStorage::DiskController#show as PNG
Parameters: {"encoded_key"=>"[FILTERED]", "filename"=>"platillo-afiliar-empresa"}
Completed 200 OK in 1ms (ActiveRecord: 0.0ms | Allocations: 203)
[ActiveJob] [ActiveStorage::AnalyzeJob] [37f30828-ff52-4c65-9144-be30425a7700] TRANSACTION (0.3ms) BEGIN
[ActiveJob] [ActiveStorage::AnalyzeJob] [37f30828-ff52-4c65-9144-be30425a7700] ActiveStorage::Blob Update (0.7ms) UPDATE "active_storage_blobs" SET "metadata" = $1 WHERE "active_storage_blobs"."id" = $2 [["metadata", "{\"identified\":true,\"width\":890,\"height\":472,\"analyzed\":true}"], ["id", 42]]
[ActiveJob] [ActiveStorage::AnalyzeJob] [37f30828-ff52-4c65-9144-be30425a7700] TRANSACTION (0.9ms) COMMIT
[ActiveJob] [ActiveStorage::AnalyzeJob] [37f30828-ff52-4c65-9144-be30425a7700] Performed ActiveStorage::AnalyzeJob (Job ID: 37f30828-ff52-4c65-9144-be30425a7700) from Async(default) in 78.82ms
Segmentation fault
Any idea?

Rails Model.update deletes nested attachment

I have a Rails 6 app.
User has_one Shop
Shop has_one_attached Logo
User.update with nested_attributes purges the User.shop.company_logo.
class User
has_one :shop, dependent: :destroy # delete Shop if user gets deleted
accepts_nested_attributes_for :shop, # also tried reject_if: :all_blank
end
class Shop
belongs_to :user
has_one_attached :company_logo do |attachable|
attachable.variant :thumbnail, resize_to_fill: [100, 100]
end
end
# creating a User
User.create({name: "Test"})
# creating a Shop
logo = File.open(Rails.root.join('spec', 'fixtures', 'files', '400x400.png'))
Shop.create(user_id: User.last.id, name: "TestShop", company_logo: logo)
User.last.shop.company_logo.attached? # returns TRUE !!!
# Update User (deletes / detaches company_logo)
params = {name: "TestUpdateName", shop: {name: "TestUpdateShop"}}
User.last.update(params)
User.last.shop.company_logo.attached? # returns FALSE !!!
Console output:
[ActiveJob] Enqueued ActiveStorage::PurgeJob (Job ID: caebfa82-7c41-4eb9-b295-c213449e0a7e) to Async(active_storage_purge) with arguments: #<GlobalID:0x00007fcf6ae179e0 #uri=#<URI::GID gid://meta-shop/ActiveStorage::Blob/81>>
ActiveStorage::Blob Load (1.7ms) SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = $1 LIMIT $2 [["id", 81], ["LIMIT", 1]]
[ActiveJob] [ActiveStorage::PurgeJob] [caebfa82-7c41-4eb9-b295-c213449e0a7e] Performing ActiveStorage::PurgeJob (Job ID: caebfa82-7c41-4eb9-b295-c213449e0a7e) from Async(active_storage_purge) enqueued at 2021-09-25T10:01:32Z with arguments: #<GlobalID:0x00007fcf5a8856b8 #uri=#<URI::GID gid://meta-shop/ActiveStorage::Blob/81>>
[ActiveJob] [ActiveStorage::PurgeJob] [caebfa82-7c41-4eb9-b295-c213449e0a7e] TRANSACTION (2.0ms) BEGIN
[ActiveJob] [ActiveStorage::PurgeJob] [caebfa82-7c41-4eb9-b295-c213449e0a7e] ActiveStorage::Attachment Exists? (2.1ms) SELECT 1 AS one FROM "active_storage_attachments" WHERE "active_storage_attachments"."blob_id" = $1 LIMIT $2 [["blob_id", 81], ["LIMIT", 1]]
[ActiveJob] [ActiveStorage::PurgeJob] [caebfa82-7c41-4eb9-b295-c213449e0a7e] ActiveStorage::Attachment Load (2.8ms) SELECT "active_storage_attachments".* FROM "active_storage_attachments" WHERE "active_storage_attachments"."record_id" = $1 AND "active_storage_attachments"."record_type" = $2 AND "active_storage_attachments"."name" = $3 LIMIT $4 [["record_id", 81], ["record_type", "ActiveStorage::Blob"], ["name", "preview_image"], ["LIMIT", 1]]
[ActiveJob] [ActiveStorage::PurgeJob] [caebfa82-7c41-4eb9-b295-c213449e0a7e] ActiveStorage::Blob Destroy (8.8ms) DELETE FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = $1 [["id", 81]]
[ActiveJob] [ActiveStorage::PurgeJob] [caebfa82-7c41-4eb9-b295-c213449e0a7e] TRANSACTION (5.1ms) COMMIT
[ActiveJob] [ActiveStorage::PurgeJob] [caebfa82-7c41-4eb9-b295-c213449e0a7e] S3 Storage (224.0ms) Deleted file from key: mx5g91bi8qwgvh6a8vzh65598kd3
[ActiveJob] [ActiveStorage::PurgeJob] [caebfa82-7c41-4eb9-b295-c213449e0a7e] S3 Storage (311.1ms) Deleted files by key prefix: variants/mx5g91bi8qwgvh6a8vzh65598kd3/
[ActiveJob] [ActiveStorage::PurgeJob] [caebfa82-7c41-4eb9-b295-c213449e0a7e] Performed ActiveStorage::PurgeJob (Job ID: caebfa82-7c41-4eb9-b295-c213449e0a7e) from Async(active_storage_purge) in 568.39ms
How can I persist the User.shop.company_logo when updating with nested_attributes ?
I found a solution:
My Shop model was replaced when updating through the parent User model. But there is an option which can be added on "one-to-one" relations like has_one. It's the update_only option, which is false by default. When using this, the nested model get updated and not replaced when using update_only: false
accepts_nested_attributes_for :shop, update_only: true
https://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html#method-i-accepts_nested_attributes_for

How do i fix the error bad URI(is not URI?): nil

Running
Rails 6.0.2.1
Ruby 2.6.5
I'm implementing photo upload using ActiveStorage and DropZoneJS but at this point, it throws an error on this particular page /users/2.
Better errors shows this
URI::InvalidURIError at /users/2
bad URI(is not URI?): nil
car model
def cover_photo(size_x, size_y)
if self.photos.length > 0
self.photos[0].variant(resize_to_limit: [size_x, size_y]).processed.service_url
else
"blank.jpg"
end
end
end
My log file
Started GET "/users/2" for ::1 at 2020-05-08 11:39:09 +0000
Processing by UsersController#show as HTML
Parameters: {"id"=>"2"}
[1m[36mUser Load (0.1ms)[0m [1m[34mSELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ?[0m [["id", 2], ["LIMIT", 1]]
↳ app/controllers/users_controller.rb:3:in `show'
Rendering users/show.html.erb within layouts/application
[1m[36mCar Load (0.1ms)[0m [1m[34mSELECT "cars".* FROM "cars" WHERE "cars"."user_id" = ?[0m [["user_id", 2]]
↳ app/views/users/show.html.erb:29
[1m[36mActiveStorage::Attachment Load (0.1ms)[0m [1m[34mSELECT "active_storage_attachments".* FROM "active_storage_attachments" WHERE "active_storage_attachments"."record_id" = ? AND "active_storage_attachments"."record_type" = ? AND "active_storage_attachments"."name" = ?[0m [["record_id", 1], ["record_type", "Car"], ["name", "photos"]]
↳ app/models/car.rb:14:in `cover_photo'
[1m[36mActiveStorage::Blob Load (0.1ms)[0m [1m[34mSELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = ? LIMIT ?[0m [["id", 26], ["LIMIT", 1]]
↳ app/models/car.rb:15:in `cover_photo'
[36m Disk Storage (0.0ms) [0m[34mChecked if file exists at key: variants/4u0kx27vmugn57zwn96o2t27mr71/36e628c6ec62cc8383a3ee5c0c8433e912780efead13846813a9f63693dd17eb (yes)[0m
[36m Disk Storage (0.5ms) [0m[34mGenerated URL for file at key: variants/4u0kx27vmugn57zwn96o2t27mr71/36e628c6ec62cc8383a3ee5c0c8433e912780efead13846813a9f63693dd17eb ()[0m
Rendered users/show.html.erb within layouts/application (Duration: 18.4ms | Allocations: 4342)
Completed 500 Internal Server Error in 21ms (ActiveRecord: 0.4ms | Allocations: 5357)
URI::InvalidURIError - bad URI(is not URI?): nil:
app/models/car.rb:15:in `cover_photo'
app/views/users/show.html.erb:36
app/views/users/show.html.erb:32
Started POST "/__better_errors/f90fad0cb966afba/variables" for ::1 at 2020-05-08 11:39:09 +0000
How do i fix this? And what is wrong with cover_photo?
Depending on your setup, I had fixed this issue by defining ActiveStorage::Current.host = "http://localhost:3000" right before the use of variant
https://github.com/rails/rails/issues/40855
Okay, i removed .service_url from
self.photos[0].variant(resize_to_limit: [size_x, size_y]).processed.service_url
So it became
self.photos[0].variant(resize_to_limit: [size_x, size_y]).processed
And now the error is gone and the page loads perfectly. Not sure why
Btw, can anyone explain?
I was having the same problem in the rails console, the solution was run this once:
ActiveStorage::Current.host = 'http://localhost:3000'
I got this information from #Jan's answer, and from here.

Partially working simple image upload using Active Storage

Any help or guidance would be most appreciated.
I've followed the Rails Guide, however, and I can upload an image to a model. However, it produces an error.
I've copied what the error suggests and that produces another error and does not upload an image.
Many, many thanks in advance!
This works but produces an error post form submission. If I hit back and then visit the specific prod id product#show the image has uploaded.
Error
NameError in ProductsController#create
undefined local variable or method `product' for # Did you mean? #product
Products.rb
def create
#list = List.find(params[:list_id])
#product = #list.products.create(product_params)
product.hero.attach(params[:hero])
redirect_to list_path(#list)
end
This does not work however, looks syntactically correct as the "#product" model attaches to the :hero .
Products.rb
def create
#list = List.find(params[:list_id])
#product = #list.products.create(product_params)
#product.hero.attach(params[:hero])
redirect_to list_path(#list)
end
creates the product
refreshes the screen back to the product list so it looks correct.
This breaks producing two errors:
The first error on products#show
ArgumentError in Products#show
Showing /Users/user/rubyonrails/shopping/app/views/products/show.html.erb where line #2 raised:
Can't resolve image into URL: to_model delegated to attachment, but the attachment is nil
Second terminal output presents the upload seems to work then something called Active Storage Purge fires up removing it?
ActiveStorage::Blob Load (0.3ms) SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = $1 LIMIT $2 [["id", 7], ["LIMIT", 1]]
[ActiveJob] [ActiveStorage::PurgeJob] [e9b35a62-ff6c-4a38-8946-3aa9c19668ef] Performing ActiveStorage::PurgeJob (Job ID: e9b35a62-ff6c-4a38-8946-3aa9c19668ef) from Async(active_storage_purge) enqueued at 2020-04-15T11:31:41Z with arguments: #<GlobalID:0x00007f92b1da3d60 #uri=#<URI::GID gid://shopping/ActiveStorage::Blob/7>>
[ActiveJob] [ActiveStorage::AnalyzeJob] [b724849f-6993-4130-bef1-a0f8837a3171] (6.4ms) COMMIT
[ActiveJob] [ActiveStorage::PurgeJob] [e9b35a62-ff6c-4a38-8946-3aa9c19668ef] (0.8ms) BEGIN
[ActiveJob] [ActiveStorage::AnalyzeJob] [b724849f-6993-4130-bef1-a0f8837a3171] Performed ActiveStorage::AnalyzeJob (Job ID: b724849f-6993-4130-bef1-a0f8837a3171) from Async(active_storage_analysis) in 15.88ms
Started GET "/lists/9" for ::1 at 2020-04-15 12:31:41 +0100
[ActiveJob] [ActiveStorage::PurgeJob] [e9b35a62-ff6c-4a38-8946-3aa9c19668ef] ActiveStorage::Attachment Exists? (0.5ms) SELECT 1 AS one FROM "active_storage_attachments" WHERE "active_storage_attachments"."blob_id" = $1 LIMIT $2 [["blob_id", 7], ["LIMIT", 1]]
Processing by ListsController#show as HTML
[ActiveJob] [ActiveStorage::PurgeJob] [e9b35a62-ff6c-4a38-8946-3aa9c19668ef] ActiveStorage::Attachment Load (1.1ms) SELECT "active_storage_attachments".* FROM "active_storage_attachments" WHERE "active_storage_attachments"."record_id" = $1 AND "active_storage_attachments"."record_type" = $2 AND "active_storage_attachments"."name" = $3 LIMIT $4 [["record_id", 7], ["record_type", "ActiveStorage::Blob"], ["name", "preview_image"], ["LIMIT", 1]]
Parameters: {"id"=>"9"}
[ActiveJob] [ActiveStorage::PurgeJob] [e9b35a62-ff6c-4a38-8946-3aa9c19668ef] ActiveStorage::Blob Destroy (1.0ms) DELETE FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = $1 [["id", 7]]
List Load (0.9ms) SELECT "lists".* FROM "lists" WHERE "lists"."id" = $1 LIMIT $2 [["id", 9], ["LIMIT", 1]]
↳ app/controllers/lists_controller.rb:7:in `show'
Product Load (0.2ms) SELECT "products".* FROM "products" WHERE "products"."id" = $1 LIMIT $2 [["id", 9], ["LIMIT", 1]]
↳ app/controllers/lists_controller.rb:8:in `show'
Rendering lists/show.html.erb within layouts/application
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
↳ app/views/lists/show.html.erb:2
Product Exists? (0.2ms) SELECT 1 AS one FROM "products" WHERE "products"."list_id" = $1 LIMIT $2 [["list_id", 9], ["LIMIT", 1]]
↳ app/views/lists/show.html.erb:5
Product Load (0.2ms) SELECT "products".* FROM "products" WHERE "products"."list_id" = $1 [["list_id", 9]]
↳ app/views/lists/show.html.erb:6
[ActiveJob] [ActiveStorage::PurgeJob] [e9b35a62-ff6c-4a38-8946-3aa9c19668ef] (6.4ms) COMMIT
(0.8ms) SELECT COUNT(*) FROM "products" WHERE "products"."list_id" = $1 [["list_id", 9]]
[ActiveJob] [ActiveStorage::PurgeJob] [e9b35a62-ff6c-4a38-8946-3aa9c19668ef] Disk Storage (0.2ms) Deleted file from key: 31cfuow9pj6vjqhq8i479fdxf1lc
↳ app/controllers/application_controller.rb:5:in `product_list_size?'
[ActiveJob] [ActiveStorage::PurgeJob] [e9b35a62-ff6c-4a38-8946-3aa9c19668ef] Disk Storage (0.1ms) Deleted files by key prefix: variants/31cfuow9pj6vjqhq8i479fdxf1lc/
Rendered lists/show.html.erb within layouts/application (Duration: 9.5ms | Allocations: 7278)
[ActiveJob] [ActiveStorage::PurgeJob] [e9b35a62-ff6c-4a38-8946-3aa9c19668ef] Performed ActiveStorage::PurgeJob (Job ID: e9b35a62-ff6c-4a38-8946-3aa9c19668ef) from Async(active_storage_purge) in 22.5ms
[Webpacker] Everything's up-to-date. Nothing to do
List item
Egg on my face.
The exclamation mark omission seems to be the issue.
from
#product = #list.products.create(product_params)
to this and it works
#product = #list.products.create!(product_params)

Ruby OAuth2 timeout error getting Token

I posted this of the issues page for the doorkeeper gem, but looking at it, I wonder if I should post here, any help would be amazing as I am completely stuck
I have been following the wiki on doorkeeper and doing the "Testing your provider with OAuth2 gem" (https://github.com/doorkeeper-gem/doorkeeper/wiki/Testing-your-provider-with-OAuth2-gem)
I am running rails 5.1.4, ruby 2.4.1, doorkeeper gem 4.2.6 and oauth2 v1.4.0
I am having issues trying to do what is done in the testing wiki in code, which is get an auth token
My sessions controller:
def new
session[:state] = 'some state sent from amazon'
session[:client_id] = 'some client id'
session[:client_secret] = 'some client secret'
session[:redirect_uri] = "#{request.base_url}/oauth/callback"
end
def create
user = User.find_by(email: params[:session][:email].downcase)
if user && user.authenticate(params[:session][:password])
if user.activated?
log_in user
redirect_to client.auth_code.authorize_url(:redirect_uri => session[:redirect_uri])
end
end
end
#route for /oauth/cllback comes here
def callback
token = client.auth_code.get_token(params[:code], :redirect_uri => session[:redirect_uri])
# testing print to screen
render json: token
end
private
def client
OAuth2::Client.new(session[:client_id], session[:client_secret], :site => request.base_url)
end
So as a user i log in, I authorise the app and then it times out and I get the following log for the whole flow:
Started GET "/login?client_id=<client_id>&response_type=code&state=<amazon state>&redirect_uri=https%3A%2F%2Fpitangui.amazon.com%2Fapi%2Fskill%2Flink%2FM2X1TLJOHDU07S" for 5.175.83.20 at 2017-10-23 13:36:35 +0100
Processing by SessionsController#new as HTML
Parameters: {"client_id"=>"<client_id>", "response_type"=>"code", "state"=>"<amazon state>", "redirect_uri"=>"https://pitangui.amazon.com/api/skill/link/M2X1TLJOHDU07S"}
Rendering sessions/new.html.erb within layouts/application
Rendered sessions/new.html.erb within layouts/application (1.5ms)
Rendered layouts/_shim.html.erb (0.5ms)
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Rendered layouts/_header.html.erb (36.3ms)
Completed 200 OK in 121ms (Views: 107.5ms | ActiveRecord: 4.0ms)
Started POST "/login" for 5.175.83.20 at 2017-10-23 13:40:35 +0100
Processing by SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"aR03Eo+jxzN+oDPrnOevHn6moTCSePoLAi2Ncc7pKbtxVQa6lLu+IzdEsfzrexpJVm6MdOugIQICyN2ZNS7hgw==", "session"=>{"email"=>"me#daviesp.co.uk", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Log In"}
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."email" = $1 LIMIT $2 [["email", "me#daviesp.co.uk"], ["LIMIT", 1]]
Redirected to https://3751d64e.ngrok.io/oauth/authorize?client_id=<client_id>&redirect_uri=https%3A%2F%2F3751d64e.ngrok.io%2Foauth%2Fcallback&response_type=code
Completed 302 Found in 67ms (ActiveRecord: 0.6ms)
Started GET "/oauth/authorize?client_id=<client_id>&redirect_uri=https%3A%2F%2F3751d64e.ngrok.io%2Foauth%2Fcallback&response_type=code" for 5.175.83.20 at 2017-10-23 13:40:36 +0100
Processing by Doorkeeper::AuthorizationsController#new as HTML
Parameters: {"client_id"=>"<client_id>", "redirect_uri"=>"https://3751d64e.ngrok.io/oauth/callback", "response_type"=>"code"}
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Doorkeeper::Application Load (0.4ms) SELECT "oauth_applications".* FROM "oauth_applications" WHERE "oauth_applications"."uid" = $1 LIMIT $2 [["uid", "6067fbe8f36b4343aa297ce76348e868f9ea04b04841adb411d0885c491c1d48"], ["LIMIT", 1]]
CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Doorkeeper::AccessToken Load (0.5ms) SELECT "oauth_access_tokens".* FROM "oauth_access_tokens" WHERE "oauth_access_tokens"."application_id" = $1 AND "oauth_access_tokens"."resource_owner_id" = $2 AND "oauth_access_tokens"."revoked_at" IS NULL ORDER BY created_at desc LIMIT $3 [["application_id", 11], ["resource_owner_id", 1], ["LIMIT", 1]]
CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
(0.2ms) BEGIN
Doorkeeper::AccessGrant Exists (0.6ms) SELECT 1 AS one FROM "oauth_access_grants" WHERE "oauth_access_grants"."token" = $1 LIMIT $2 [["token", "a6bd0459570f1e0116ca6b2cade1e60ae83ba439d3c70b750046cfffe3cc85e4"], ["LIMIT", 1]]
SQL (0.5ms) INSERT INTO "oauth_access_grants" ("resource_owner_id", "application_id", "token", "expires_in", "redirect_uri", "created_at", "scopes") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["resource_owner_id", 1], ["application_id", 11], ["token", "a6bd0459570f1e0116ca6b2cade1e60ae83ba439d3c70b750046cfffe3cc85e4"], ["expires_in", 600], ["redirect_uri", "https://3751d64e.ngrok.io/oauth/callback"], ["created_at", "2017-10-23 12:40:36.235539"], ["scopes", ""]]
(1.5ms) COMMIT
Redirected to https://3751d64e.ngrok.io/oauth/callback?code=a6bd0459570f1e0116ca6b2cade1e60ae83ba439d3c70b750046cfffe3cc85e4
Completed 302 Found in 14ms (ActiveRecord: 4.2ms)
Started GET "/oauth/callback?code=[FILTERED]" for 5.175.83.20 at 2017-10-23 13:40:36 +0100
Processing by SessionsController#oauth_call as HTML
Parameters: {"code"=>"[FILTERED]"}
Started POST "/oauth/token" for 5.175.83.20 at 2017-10-23 13:40:37 +0100
Completed 500 Internal Server Error in 60406ms (ActiveRecord: 0.0ms)
Faraday::TimeoutError (Net::ReadTimeout)
Cant for the life of me figure out why it works in irb but not in code. Here is what i do in irb
irb(main):001:0> require 'oauth2'
=> true
irb(main):002:0>
irb(main):003:0* client_id = '6067fbe8f36b4343aa297ce76348e868f9ea04b04841adb411d0885c491c1d48'
=> "6067fbe8f36b4343aa297ce76348e868f9ea04b04841adb411d0885c491c1d48"
irb(main):004:0> client_secret = '937088f4b7579b8922ad02518477da7be699958df1b1e8a85da34f2e8b4ce086'
=> "937088f4b7579b8922ad02518477da7be699958df1b1e8a85da34f2e8b4ce086"
irb(main):005:0> redirect_uri = 'https://3751d64e.ngrok.io/oauth/callback'
=> "https://3751d64e.ngrok.io/oauth/callback"
irb(main):006:0> site = 'https://3751d64e.ngrok.io'
=> "https://3751d64e.ngrok.io"
irb(main):007:0> state = 'some state'
=> "some state"
irb(main):008:0> client = OAuth2::Client.new(client_id, client_secret, :site => site)
=> #<OAuth2::Client:0x007fa61414c4b0 #id="6067fbe8f36b4343aa297ce76348e868f9ea04b04841adb411d0885c491c1d48", #secret="937088f4b7579b8922ad02518477da7be699958df1b1e8a85da34f2e8b4ce086", #site="https://3751d64e.ngrok.io", #options={:authorize_url=>"/oauth/authorize", :token_url=>"/oauth/token", :token_method=>:post, :auth_scheme=>:request_body, :connection_opts=>{}, :connection_build=>nil, :max_redirects=>5, :raise_errors=>true}>
irb(main):009:0> client.auth_code.authorize_url(:redirect_uri => redirect_uri)
=> "https://3751d64e.ngrok.io/oauth/authorize?client_id=6067fbe8f36b4343aa297ce76348e868f9ea04b04841adb411d0885c491c1d48&redirect_uri=https%3A%2F%2F3751d64e.ngrok.io%2Foauth%2Fcallback&response_type=code"
even If i put that uri into browser and it returns the access token:
{"token_type":"bearer","created_at":1508763209,"access_token":"38282cae5191923f1f358aece869e237d4d9742cdd7c918ae63104c57807a826","refresh_token":null,"expires_at":1508770409}
Again any help would be amazing!
So I found in my Dev Environment, if i stop using puma and rails server and started using POW, the issue went away. I checked if puma was running as single thread but it was running 5 threads, so not sure why this was happening.

Resources