[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[reclaim-oidc] 03/18: towards working tool
From: |
gnunet |
Subject: |
[reclaim-oidc] 03/18: towards working tool |
Date: |
Sat, 12 Jun 2021 00:40:39 +0200 |
This is an automated email from the git hooks/post-receive script.
martin-schanzenbach pushed a commit to branch master
in repository reclaim-oidc.
commit cd02c836de772007c472553bcbe976ccb18589d7
Author: Schanzenbach, Martin <mschanzenbach@posteo.de>
AuthorDate: Fri Apr 26 00:16:00 2019 +0200
towards working tool
---
bin/reclaim-oidc | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++
lib/reclaim_oidc.rb | 82 +++++++++++++++++++++++++++++++++
2 files changed, 211 insertions(+)
diff --git a/bin/reclaim-oidc b/bin/reclaim-oidc
old mode 100644
new mode 100755
index e69de29..7ce6d57
--- a/bin/reclaim-oidc
+++ b/bin/reclaim-oidc
@@ -0,0 +1,129 @@
+#!/usr/bin/env ruby
+require 'optparse'
+require './lib/reclaim_oidc.rb'
+
+class OptParser
+ class ScriptOptions
+ attr_accessor :name, :add, :delete, :list, :description, :redirect_uri,
+ :verbose
+
+ def initialize
+ self.delete = false
+ self.add = false
+ self.list = false
+ self.verbose = false
+ end
+
+ def define_options(parser)
+ parser.banner = "Usage: reclaim-oidc [options]"
+ parser.separator ""
+ parser.separator "Specific options:"
+
+ # add additional options
+ add_option(parser)
+ delete_option(parser)
+ list_option(parser)
+ client_name_option(parser)
+ client_redirect_option(parser)
+ client_description_option(parser)
+ boolean_verbose_option(parser)
+
+ parser.separator ""
+ parser.separator "Common options:"
+ # No argument, shows at tail. This will print an options summary.
+ parser.on_tail("-h", "--help", "Show this message") do
+ puts parser
+ exit
+ end
+ # Another typical switch to print the version.
+ parser.on_tail("--version", "Show version") do
+ puts ReclaimOidc.version
+ exit
+ end
+ end
+
+ def client_name_option(parser)
+ parser.on("-n", "--client-name [NAME]",
+ "Name of the OIDC client") do |n|
+ self.name = n
+ end
+ end
+
+ def client_redirect_option(parser)
+ parser.on("-r", "--redirect [URI]",
+ "The OIDC redirect_uri parameter") do |n|
+ self.redirect_uri = n
+ end
+ end
+
+ def client_description_option(parser)
+ parser.on("-D", "--description [DESCRIPTION]",
+ "The OIDC client description") do |n|
+ self.description = n
+ end
+ end
+
+ def add_option(parser)
+ parser.on("-a", "--add", "Add a client") do |v|
+ self.add = v
+ end
+ end
+
+ def delete_option(parser)
+ parser.on("-d", "--delete", "Delete a client") do |v|
+ self.delete = v
+ end
+ end
+
+ def list_option(parser)
+ parser.on("-l", "--list", "List clients") do |v|
+ self.list = v
+ end
+ end
+
+ def boolean_verbose_option(parser)
+ # Boolean switch.
+ parser.on("-v", "--[no-]verbose", "Run verbosely") do |v|
+ self.verbose = v
+ end
+ end
+ end
+
+ #
+ # Return a structure describing the options.
+ #
+ def parse(args)
+ # The options specified on the command line will be collected in
+ # *options*.
+
+ @options = ScriptOptions.new
+ @args = OptionParser.new do |parser|
+ @options.define_options(parser)
+ parser.parse!(args)
+ end
+ @options
+ end
+
+ attr_reader :parser, :options
+end # class OptparseExample
+
+op = OptParser.new
+options = op.parse(ARGV)
+#pp options
+#pp ARGV
+
+x = ReclaimOidc.new(options.verbose)
+
+if (options.list)
+ x.get_clients
+ exit
+end
+if (options.add)
+ raise if options.name.nil? or options.redirect_uri.nil?
+ x.add_client(options.name,options.redirect_uri,options.description)
+ exit
+end
+if (options.delete)
+ x.delete_client(options.name)
+end
+
diff --git a/lib/reclaim_oidc.rb b/lib/reclaim_oidc.rb
index a2ac414..1afa68b 100644
--- a/lib/reclaim_oidc.rb
+++ b/lib/reclaim_oidc.rb
@@ -1,5 +1,87 @@
+require 'net/http'
+require 'json'
+
class ReclaimOidc
+ def initialize(verbose=false, url='http://localhost:7776')
+ @verbose = verbose
+ @url = url
+ end
def self.hello
puts "Hello World!"
end
+ def parse_identities_from_http(body)
+ arr = JSON.parse(body)
+ ids = []
+ arr.each do |obj|
+ ids << ReclaimOidc::Client.from_json(obj)
+ end
+ ids
+ end
+ def get_clients
+ uri = URI(@url + '/identity/all')
+ ids = parse_identities_from_http(Net::HTTP.get(uri))
+ ids.each do |id|
+ uri = URI(@url + "/namestore/#{id.name}")
+ id.parse_client_info(JSON.parse(Net::HTTP.get(uri)))
+ next if id.redirect_uri.nil?
+ puts "name: #{id.name}"
+ puts "client_id: #{id.key}"
+ puts "description: #{id.description}"
+ puts "redirect_uri: #{id.redirect_uri}"
+ end
+ end
+ def add_client(name,redirect_uri,description)
+ raise if redirect_uri.nil? or description.nil? or name.nil?
+ uri = URI(@url + '/identity')
+ payload = {'name' => "#{name}"}.to_json
+ resp = Net::HTTP.post(uri, payload)
+ uri = URI(@url + "/namestore/#{name}")
+ record = {'record_type' => "RECLAIM_OIDC_CLIENT",
+ 'value' => description,
+ 'record_name' => "@",
+ 'expiration_time' => "1d",
+ 'flag' => 8}
+ resp = Net::HTTP.post(uri,record.to_json)
+ record = {'record_type' => "RECLAIM_OIDC_REDIRECT",
+ 'value' => redirect_uri,
+ 'record_name' => "@",
+ 'expiration_time' => "1d",
+ 'flag' => 8}
+ resp = Net::HTTP.post(uri,record.to_json)
+ end
+ def delete_client(name)
+ raise if name.nil?
+ uri = URI(@url + "/identity/name/#{name}")
+ Net::HTTP.start(uri.host, uri.port) do |http|
+ request = Net::HTTP::Delete.new uri
+ resp = http.request request # Net::HTTPResponse object
+ end
+ end
+ def get_jwt_secret
+ raise
+ end
+ def set_jwt_secret
+ raise
+ end
+
+ class Client
+ attr_reader :name, :key, :description, :redirect_uri
+ def initialize(name, key)
+ @name = name
+ @key = key
+ end
+ def self.from_json(obj)
+ id = Client.new(obj['name'], obj['pubkey'])
+ end
+ def parse_client_info(obj)
+ obj.each do |record|
+ if (record['record_type'] == 'RECLAIM_OIDC_CLIENT')
+ @description = record['value']
+ end
+ if (record['record_type'] == 'RECLAIM_OIDC_REDIRECT')
+ @redirect_uri = record['value']
+ end
+ end
+ end
+ end
end
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [reclaim-oidc] branch master created (now 016209d), gnunet, 2021/06/11
- [reclaim-oidc] 01/18: Initial commit, gnunet, 2021/06/11
- [reclaim-oidc] 04/18: minor, gnunet, 2021/06/11
- [reclaim-oidc] 06/18: ready for deploy, gnunet, 2021/06/11
- [reclaim-oidc] 05/18: integrate config, gnunet, 2021/06/11
- [reclaim-oidc] 03/18: towards working tool,
gnunet <=
- [reclaim-oidc] 09/18: 0.0.4, gnunet, 2021/06/11
- [reclaim-oidc] 17/18: Merge branch 'master' into 'master', gnunet, 2021/06/11
- [reclaim-oidc] 08/18: old style posts, gnunet, 2021/06/11
- [reclaim-oidc] 07/18: 0.0.2, gnunet, 2021/06/11
- [reclaim-oidc] 15/18: Merge branch 'master' into 'master', gnunet, 2021/06/11
- [reclaim-oidc] 11/18: 0.0.5, gnunet, 2021/06/11
- [reclaim-oidc] 12/18: update readme, gnunet, 2021/06/11
- [reclaim-oidc] 13/18: add image, gnunet, 2021/06/11
- [reclaim-oidc] 02/18: add license and readme, gnunet, 2021/06/11
- [reclaim-oidc] 18/18: update to v0.0.7, gnunet, 2021/06/11