Oauth2无效授予门卫

时间:2013-07-31 15:23:46

标签: ruby sinatra oauth-2.0 doorkeeper

当我尝试从我的api获取资源时,我获得了无效的资助。

invalid_grant: The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request,or was issued to another client.

可能是什么问题?

  require 'sinatra'
  require 'httparty'
  require 'oauth2'

  enable :sessions

  configure do
    set :callback, 'http://localhost:4567/auth/doorkeeper/callback'
    set :app_id, '7cd423ef68bdc938372d8e290475ea5a85feb550004b77481f99ff0dcba133b1'
    set :app_secret, '46bafd07b5a485240d7fdaedbdbac2a675afabe470f5433b13395f8dcff4e473'
  end

  get '/' do
    oauth_client.auth_code.authorize_url(redirect_uri: settings.callback)
  end

  get '/auth/doorkeeper/callback' do
    if params[:code].nil?
      redirect to('/')
    end

    session[:code] = params[:code]

    redirect to('/get_token')
  end

  get '/get_token' do
    access = oauth_client.auth_code.get_token session[:code], :redirect_uri => settings.callback
    # session[:code]
    access.get('/api/v1/me')
  end

  def oauth_client
    @oauth_client ||= OAuth2::Client.new(settings.app_id, settings.app_secret, site: "http://localhost:3000")
  end

0 个答案:

没有答案