gnunet-svn
[Top][All Lists]
Advanced

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

[reclaim-oidc] 14/18: added command for changing the jwt secret


From: gnunet
Subject: [reclaim-oidc] 14/18: added command for changing the jwt secret
Date: Sat, 12 Jun 2021 00:40:50 +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 517b8bb6108cbdfdb14e117f36e4ec57d04bf838
Author: Alexia Pagkopoulou <a.pagkopoulou@tum.de>
AuthorDate: Wed Aug 21 13:16:29 2019 +0200

    added command for changing the jwt secret
---
 README.md           |  6 ++++++
 bin/reclaim-oidc    | 17 ++++++++++++++---
 lib/reclaim_oidc.rb | 11 ++++++++---
 3 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/README.md b/README.md
index 0b30e4b..64c986f 100644
--- a/README.md
+++ b/README.md
@@ -28,3 +28,9 @@ Delete a client:
 ```
 $ reclaim-oidc --delete --client-name myclient
 ```
+
+## Change the JSON-Web-Token secret
+To change the JWT secret key:
+```
+$ reclaim-oidc --jwt-secret new_jwt_secret
+```
diff --git a/bin/reclaim-oidc b/bin/reclaim-oidc
index b279b31..749c7e9 100755
--- a/bin/reclaim-oidc
+++ b/bin/reclaim-oidc
@@ -5,13 +5,14 @@ require 'reclaim_oidc'
 class OptParser
   class ScriptOptions
     attr_accessor :name, :add, :delete, :list, :description, :redirect_uri,
-                  :verbose
+                  :verbose, :jwt_secret
 
     def initialize
       self.delete = false
       self.add = false
       self.list = false
       self.verbose = false
+      self.jwt_secret = false
     end
 
     def define_options(parser)
@@ -27,6 +28,7 @@ class OptParser
       client_redirect_option(parser)
       client_description_option(parser)
       boolean_verbose_option(parser)
+      jwt_secret_option(parser)
 
       parser.separator ""
       parser.separator "Common options:"
@@ -87,7 +89,13 @@ class OptParser
         self.verbose = v
       end
     end
-  end
+  
+    def jwt_secret_option(parser)
+      parser.on("-j", "--jwt-secret [JWT-SECRET]", "Set JWT secret") do |v|
+        self.jwt_secret = v
+      end
+    end
+  end  
 
   #
   # Return a structure describing the options.
@@ -152,4 +160,7 @@ if (options.delete)
   roidc.delete_client(options.name)
   puts "OK"
 end
-
+if (options.jwt_secret)
+  roidc.set_jwt_secret(options.jwt_secret)
+  puts "JWT secret has been changed"
+end
diff --git a/lib/reclaim_oidc.rb b/lib/reclaim_oidc.rb
index c7ccaaf..fa91c05 100644
--- a/lib/reclaim_oidc.rb
+++ b/lib/reclaim_oidc.rb
@@ -85,9 +85,14 @@ class ReclaimOidc
     op['token_endpoint'] = host + '/openid/token'
     op['userinfo_endpoint'] = host + '/openid/userinfo'
     op
-  end
-  def set_jwt_secret
-    raise
+  end  
+  def set_jwt_secret(jwt_secret)
+    uri = URI(@url + '/config/reclaim-rest-plugin')
+    request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
+    request.body = {"JWT_SECRET": jwt_secret}.to_json
+    resp = Net::HTTP.start(uri.host, uri.port) do |http|
+      http.request request
+    end
   end
 
   class Client

-- 
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]