gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[reclaim-oidc] 05/18: integrate config


From: gnunet
Subject: [reclaim-oidc] 05/18: integrate config
Date: Sat, 12 Jun 2021 00:40:41 +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 ace6acf6680db4028901a6f2211c03db850b1461
Author: Schanzenbach, Martin <mschanzenbach@posteo.de>
AuthorDate: Fri Apr 26 12:17:13 2019 +0200

    integrate config
---
 bin/reclaim-oidc    | 35 ++++++++++++++++++++++++++++++-----
 lib/reclaim_oidc.rb | 35 ++++++++++++++++++++++++++---------
 2 files changed, 56 insertions(+), 14 deletions(-)

diff --git a/bin/reclaim-oidc b/bin/reclaim-oidc
index 179ad5d..817d40d 100755
--- a/bin/reclaim-oidc
+++ b/bin/reclaim-oidc
@@ -112,18 +112,43 @@ options = op.parse(ARGV)
 #pp options
 #pp ARGV
 
-x = ReclaimOidc.new(options.verbose)
+roidc = ReclaimOidc.new(options.verbose)
 
 if (options.list)
-  x.get_clients
+  op = roidc.get_op_info
+  puts "OpenID Connect Provider Information:"
+  puts "------------------------------------"
+  puts "Authorize Endpoint: #{op['authz_endpoint']}"
+  puts "Token Endpoint: #{op['token_endpoint']}"
+  puts "JSON-Web-Token Algorithm: #{op['jwt_algo']}"
+  puts "JSON-Web-Token key: #{op['jwt_key']}"
+  puts "Example Authorization Redirect:"
+  puts 
"https://api.reclaim/openid/authorize?client_id=<client_id>&redirect_uri=<redirect_uri>&scope=email%20full_name&nonce=1234"
+  puts ""
+  puts "Registered Clients:"
+  puts "-------------------"
+  clients = roidc.get_clients
+  clients.each do |client|
+    puts "name: #{client.name}"
+    puts "client_id: #{client.key}"
+    puts "client_secret: #{client.secret}"
+    puts "description: #{client.description}"
+    puts "redirect_uri: #{client.redirect_uri}"
+    puts "---"
+  end
   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)
+  if options.name.nil? or options.redirect_uri.nil?
+    puts "ERROR: Missing options"
+    exit
+  end
+  roidc.add_client(options.name,options.redirect_uri,options.description)
+  puts "OK"
   exit
 end
 if (options.delete)
-  x.delete_client(options.name)
+  roidc.delete_client(options.name)
+  puts "OK"
 end
 
diff --git a/lib/reclaim_oidc.rb b/lib/reclaim_oidc.rb
index 1afa68b..08a3e06 100644
--- a/lib/reclaim_oidc.rb
+++ b/lib/reclaim_oidc.rb
@@ -5,6 +5,7 @@ class ReclaimOidc
   def initialize(verbose=false, url='http://localhost:7776')
     @verbose = verbose
     @url = url
+    @client_secret = get_client_secret()
   end
   def self.hello
     puts "Hello World!"
@@ -13,22 +14,29 @@ class ReclaimOidc
     arr = JSON.parse(body)
     ids = []
     arr.each do |obj|
+      obj["secret"] = @client_secret
       ids << ReclaimOidc::Client.from_json(obj)
     end
     ids
   end
+
+  def get_client_secret
+    uri = URI(@url + '/config/reclaim-rest-plugin')
+    resp = JSON.parse Net::HTTP.get(uri)
+    return resp["PSW"]
+  end
+
   def get_clients
     uri = URI(@url + '/identity/all')
     ids = parse_identities_from_http(Net::HTTP.get(uri))
+    result = []
     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}"
+      result << id
     end
+    result
   end
   def add_client(name,redirect_uri,description)
     raise if redirect_uri.nil? or description.nil? or name.nil?
@@ -57,21 +65,30 @@ class ReclaimOidc
       resp = http.request request # Net::HTTPResponse object
     end
   end
-  def get_jwt_secret
-    raise
+  def get_op_info
+    uri = URI(@url + '/config/reclaim-rest-plugin')
+    resp = JSON.parse Net::HTTP.get(uri)
+    op = {}
+    op['jwt_key'] = resp["JWT_SECRET"]
+    op['jwt_algo'] = 'HS512' # FIXME
+    host = 'http://localhost:7776'
+    op['authz_endpoint'] = host + '/openid/authorize'
+    op['token_endpoint'] = host + '/openid/token'
+    op
   end
   def set_jwt_secret
     raise
   end
 
   class Client
-    attr_reader      :name, :key, :description, :redirect_uri
-    def initialize(name, key)
+    attr_reader      :name, :key, :description, :redirect_uri, :secret
+    def initialize(name, key, secret)
       @name = name
       @key = key
+      @secret = secret
     end
     def self.from_json(obj)
-      id = Client.new(obj['name'], obj['pubkey'])
+      id = Client.new(obj['name'], obj['pubkey'], obj['secret'])
     end
     def parse_client_info(obj)
       obj.each do |record|

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]