Sha256: 2d9dafb05b292dae96eda7fcec219670a2b61cdc823c1c0b8317d01fd8b2618f

Contents?: true

Size: 855 Bytes

Versions: 30

Compression:

Stored size: 855 Bytes

Contents

module OpenIDConnect
  class AccessToken < Rack::OAuth2::AccessToken::Bearer
    attr_required :client
    attr_optional :id_token

    def initialize(attributes = {})
      super
      @token_type = :bearer
    end

    def userinfo!(params = {})
      hash = resource_request do
        get client.userinfo_uri, params
      end
      ResponseObject::UserInfo.new hash
    end

    private

    def resource_request
      res = yield
      case res.status
      when 200
        JSON.parse(res.body).with_indifferent_access
      when 400
        raise BadRequest.new('API Access Faild', res)
      when 401
        raise Unauthorized.new('Access Token Invalid or Expired', res)
      when 403
        raise Forbidden.new('Insufficient Scope', res)
      else
        raise HttpError.new(res.status, 'Unknown HttpError', res)
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
openid_connect-2.0.0 lib/openid_connect/access_token.rb
openid_connect-2.0.0.rc1 lib/openid_connect/access_token.rb
openid_connect-1.4.2 lib/openid_connect/access_token.rb
openid_connect-1.4.1 lib/openid_connect/access_token.rb
openid_connect-1.4.0 lib/openid_connect/access_token.rb
openid_connect-1.3.1 lib/openid_connect/access_token.rb
openid_connect-1.3.0 lib/openid_connect/access_token.rb
openid_connect-1.2.0 lib/openid_connect/access_token.rb
openid_connect-1.1.8 lib/openid_connect/access_token.rb
openid_connect-1.1.7 lib/openid_connect/access_token.rb
openid_connect-1.1.6 lib/openid_connect/access_token.rb
openid_connect-1.1.5 lib/openid_connect/access_token.rb
openid_connect-1.1.4 lib/openid_connect/access_token.rb
openid_connect-1.1.3 lib/openid_connect/access_token.rb
openid_connect-1.1.2 lib/openid_connect/access_token.rb
openid_connect-1.1.1 lib/openid_connect/access_token.rb
openid_connect-1.1.0 lib/openid_connect/access_token.rb
openid_connect-1.0.3 lib/openid_connect/access_token.rb
openid_connect-1.0.2 lib/openid_connect/access_token.rb
openid_connect-1.0.1 lib/openid_connect/access_token.rb