{"action":"created","issue":{"url":"https://api.github.com/repos/jwickard/omniauth-wordpress-oauth2-plugin/issues/10","labels_url":"https://api.github.com/repos/jwickard/omniauth-wordpress-oauth2-plugin/issues/10/labels{/name}","comments_url":"https://api.github.com/repos/jwickard/omniauth-wordpress-oauth2-plugin/issues/10/comments","events_url":"https://api.github.com/repos/jwickard/omniauth-wordpress-oauth2-plugin/issues/10/events","html_url":"https://github.com/jwickard/omniauth-wordpress-oauth2-plugin/issues/10","id":93104266,"number":10,"title":"invalid_credentials: Unknown request","user":{"login":"bkno","id":426436,"avatar_url":"https://avatars.githubusercontent.com/u/426436?v=3","gravatar_id":"","url":"https://api.github.com/users/bkno","html_url":"https://github.com/bkno","followers_url":"https://api.github.com/users/bkno/followers","following_url":"https://api.github.com/users/bkno/following{/other_user}","gists_url":"https://api.github.com/users/bkno/gists{/gist_id}","starred_url":"https://api.github.com/users/bkno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bkno/subscriptions","organizations_url":"https://api.github.com/users/bkno/orgs","repos_url":"https://api.github.com/users/bkno/repos","events_url":"https://api.github.com/users/bkno/events{/privacy}","received_events_url":"https://api.github.com/users/bkno/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-07-05T11:32:37Z","updated_at":"2015-08-26T07:28:36Z","closed_at":null,"body":"Hi,\r\n\r\nI'm having a bit of a nightmare getting this working, probably something fundamental I'm missing on the Rails end.\r\n\r\nWhen I visit `/auth/wordpress_hosted` it successfully goes to WordPress and logs in, then returns to Rails, but shows this error: `Could not authenticate you from WordpressHosted because \"Invalid credentials\".`\r\n\r\nThere's a more specific error in the logs `Unknown request`:\r\n\r\n```\r\nStarted GET \"/users/auth/wordpress_hosted/callback?code=852b0819f536d44d4c6daa19a648c0c9d42fbae4&state=b79bf1b2824dd58c983263cc9e2e4bd71156b9d6e174a964\"\r\n\r\nINFO -- omniauth: (wordpress_hosted) Callback phase initiated.\r\n\r\nERROR -- omniauth: (wordpress_hosted) Authentication failure! invalid_credentials: OAuth2::Error, invalid_request: Unknown request\r\n\r\n{\"error\":\"invalid_request\",\"error_description\":\"Unknown request\"}\r\n```\r\n\r\n**Gems:**\r\ndevise 3.5.1\r\nomniauth-wordpress_hosted 0.0.2 from git://github.com/jwickard/omniauth-wordpress-oauth2-plugin.git\r\noauth2 1.0.0\r\nomniauth 1.2.2\r\nomniauth-oauth2 1.3.1\r\n\r\n**WP:**\r\nWordPress 4.2.2\r\nWordPress OAuth Server 3.1.3\r\n\r\n**Host:**\r\nI've tried WordPress on both Tsohost and Pantheon.\r\n\r\n**devise.rb:**\r\n```ruby\r\n  config.omniauth :wordpress_hosted, ENV['OAUTH_ID'], ENV['OAUTH_SECRET'],\r\n                  strategy_class: OmniAuth::Strategies::WordpressHosted, \r\n                  client_options: { site: 'http://my-site.com' }\r\n```\r\nHave also tried putting the keys directly in here as strings.\r\n\r\n**omniauth_callbacks_controller.rb:**\r\n```ruby\r\nclass OmniauthCallbacksController < Devise::OmniauthCallbacksController\r\n  def wordpress_hosted\r\n    @user = User.find_for_wordpress_hosted(request.env[\"omniauth.auth\"], current_user)\r\n    if @user.persisted?\r\n      flash[:notice] = I18n.t \"devise.omniauth_callbacks.success\", :kind => \"Wordpress Hosted\"\r\n      sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated\r\n    else\r\n      session[\"devise.wordpress_hosted_data\"] = request.env[\"omniauth.auth\"]\r\n      redirect_to new_user_registration_url\r\n    end\r\n  end\r\nend\r\n```\r\n\r\n**user.rb:**\r\n```ruby\r\n:omniauth_providers => [:wordpress_hosted]\r\n```\r\n..\r\nI tried putting debug lines in and this block doesn't get executed:\r\n```ruby\r\n def self.find_for_wordpress_hosted(oauth, signed_in_user=nil)\r\n    if signed_in_user\r\n      return signed_in_user\r\n    else\r\n      user = User.find_by_uid(oauth['uid'])\r\n      if user.nil?\r\n        user = User.create!(email: oauth['info']['email'], uid: oauth['uid'], firstname: 'test', lastname: 'test')\r\n      end\r\n      user\r\n    end\r\n  end\r\n```\r\n\r\n**routes.rb:**\r\n```ruby\r\ndevise_for :users, controllers: { omniauth_callbacks: 'omniauth_callbacks' }\r\n```\r\n\r\nThe doc says `wordpress_oauth2` a few times, I ran into some prior problems with this (passthru error) but changing it to `wordpress_hosted` got me to the point where everything runs and I get the Unknown request error."},"comment":{"url":"https://api.github.com/repos/jwickard/omniauth-wordpress-oauth2-plugin/issues/comments/134875799","html_url":"https://github.com/jwickard/omniauth-wordpress-oauth2-plugin/issues/10#issuecomment-134875799","issue_url":"https://api.github.com/repos/jwickard/omniauth-wordpress-oauth2-plugin/issues/10","id":134875799,"user":{"login":"atzorvas","id":527550,"avatar_url":"https://avatars.githubusercontent.com/u/527550?v=3","gravatar_id":"","url":"https://api.github.com/users/atzorvas","html_url":"https://github.com/atzorvas","followers_url":"https://api.github.com/users/atzorvas/followers","following_url":"https://api.github.com/users/atzorvas/following{/other_user}","gists_url":"https://api.github.com/users/atzorvas/gists{/gist_id}","starred_url":"https://api.github.com/users/atzorvas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atzorvas/subscriptions","organizations_url":"https://api.github.com/users/atzorvas/orgs","repos_url":"https://api.github.com/users/atzorvas/repos","events_url":"https://api.github.com/users/atzorvas/events{/privacy}","received_events_url":"https://api.github.com/users/atzorvas/received_events","type":"User","site_admin":false},"created_at":"2015-08-26T07:28:36Z","updated_at":"2015-08-26T07:28:36Z","body":"@bkno solved for me, https://github.com/bkno/omniauth-wordpress-oauth2-plugin/compare/master...atzorvas:master"}}