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-1.0.0 lib/openid_connect/access_token.rb
openid_connect-0.12.0 lib/openid_connect/access_token.rb
openid_connect-0.11.2 lib/openid_connect/access_token.rb
openid_connect-0.11.1 lib/openid_connect/access_token.rb
openid_connect-0.11.0 lib/openid_connect/access_token.rb
openid_connect-0.10.0 lib/openid_connect/access_token.rb
openid_connect-0.9.2 lib/openid_connect/access_token.rb
openid_connect-0.9.1 lib/openid_connect/access_token.rb
openid_connect-0.9.0 lib/openid_connect/access_token.rb
openid_connect-0.8.3 lib/openid_connect/access_token.rb