Created
August 8, 2022 23:31
-
-
Save WilliamNHarvey/5e86f5038c03bd0c68caad1d70977382 to your computer and use it in GitHub Desktop.
DPoP on browser with Rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/WilliamNHarvey/dpop-ruby | |
class MyController < ApplicationController | |
include Dpop::Controller | |
ensure_dpop! | |
def index | |
uri = URI("https://www.myresourcehost.com/index?page=1") | |
proof = get_proof(htu: dpop_htu(uri), htm: "GET") | |
req = Net::HTTP::Get.new(uri) | |
req['authorization'] = "DPoP #{my_access_token}" | |
req['dpop'] = proof | |
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http| | |
http.request(req) | |
end | |
@data = res.body | |
end | |
def create | |
uri = URI("https://www.myresourcehost.com/index?page=1") | |
proof = get_proof(htu: dpop_htu(uri), htm: "GET") | |
req = Net::HTTP::Post.new(uri) | |
req['authorization'] = "DPoP #{my_access_token}" | |
req['dpop'] = proof | |
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http| | |
http.request(req) | |
end | |
@data = res.body | |
end | |
private | |
# Only pass scheme, host, and path following DPoP spec | |
def dpop_htu(uri) | |
uri.fragment = dpop_uri.query = nil | |
uri | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment