Class: OmniAuth::Strategies::Nft

Inherits:
Object
  • Object
show all
Includes:
OmniAuth::Strategy
Defined in:
lib/omniauth/strategies/nft.rb

Overview

An OmniAuth strategy for authenticating via NFT ownership

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#addressObject (readonly)

def request_phase

checker = NftChecker.init(options.checker_type, options.checker_options)
# checker.list_nfts({slug: 'untitled-collection-4919696'}, '0x051c6B791044102Ae773e27FEA21480ed6D653F4'
raise 'party 2!'

end



29
30
31
# File 'lib/omniauth/strategies/nft.rb', line 29

def address
  @address
end

#nftObject (readonly)

def request_phase

checker = NftChecker.init(options.checker_type, options.checker_options)
# checker.list_nfts({slug: 'untitled-collection-4919696'}, '0x051c6B791044102Ae773e27FEA21480ed6D653F4'
raise 'party 2!'

end



29
30
31
# File 'lib/omniauth/strategies/nft.rb', line 29

def nft
  @nft
end

Instance Method Details

#callback_phaseObject

rubocop:disable Metrics/AbcSize,Metrics/MethodLength



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/omniauth/strategies/nft.rb', line 49

def callback_phase # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  nft_params = ActionController::Parameters.new(request.params).permit(:address, :nft_id, :nft_contract, :sig)
  return fail!(:no_wallet_address) if nft_params[:address].blank?
  return fail!(:no_nft) if nft_params[:nft_id].blank? || nft_params[:nft_contract].blank?

   = { contract_address: nft_params[:nft_contract], token_id: nft_params[:nft_id] }
  nft = checker.fetch_nft_for_owner(nft_params[:address], )
  return fail!(:invalid_nft) if nft.blank?

  # At this point, we know the users owns the NFT, but not if it's part of our collection
  return fail!(:not_in_collection) unless verify_collection(nft["collection"])

  # Now we have verified the address owns the NFT and that the NFT is in our collection
  return fail!(:invalid_signature) unless verify_signature(nft_params[:address], session["nft__sig_message"],
                                                           nft_params[:sig])

  # And, completing the validation, we know the current user session owns the owning wallet
  @address = nft_params[:address]
  @nft = nft
  super
end

#request_phaseObject

option :form, OmniAuth::Nft::NftController.action(:request_phase) option :form, true



19
20
21
# File 'lib/omniauth/strategies/nft.rb', line 19

def request_phase
  OmniAuth::Nft::NftController.action(:request_phase).call(env)
end