mirror of
https://github.com/jpace121/j7s-jwt-mosquitto-auth.git
synced 2026-11-03 15:27:46 +00:00
Add program to generate long lived tokens. Use python to get a token directly.
This commit is contained in:
1 parent
bfb110d061
commit
c76ff553cc
7 files changed
+184
-9
No files matched your search
+12
-7
@@ -1,12 +1,17 @@
|
||||
per_listener_settings true
|
||||
log_type all
|
||||
|
||||
listener 8082
|
||||
protocol websockets
|
||||
|
||||
listener 8081
|
||||
protocol mqtt
|
||||
|
||||
log_type all
|
||||
allow_anonymous true
|
||||
|
||||
allow_anonymous false
|
||||
auth_plugin /home/jimmy/Develop/mosquitto-plugin/build/libj7s-plugin.so
|
||||
auth_opt_issuer https://auth.jpace121.net/realms/jpace121-main
|
||||
auth_opt_public_key /home/jimmy/Develop/mosquitto-plugin/test/key.pem
|
||||
|
||||
listener 8081
|
||||
protocol mqtt
|
||||
allow_anonymous false
|
||||
auth_plugin /home/jimmy/Develop/mosquitto-plugin/build/libj7s-plugin.so
|
||||
auth_opt_issuer https://auth.jpace121.net/realms/jpace121-main
|
||||
auth_opt_public_key /home/jimmy/Develop/mosquitto-plugin/test/key.pem
|
||||
|
||||
File renamed without changes.
@@ -0,0 +1,36 @@
|
||||
import requests
|
||||
import json
|
||||
import time
|
||||
import paho.mqtt.client
|
||||
import time
|
||||
|
||||
# RESULT=`curl --cacert ./ca.pem --cert jimmy-client.pem --key jimmy-client-key.pem --data "grant_type=password&client_id=test&username=jimmy&password=1234" https://nginx-test.internal.jpace121.net:8443/realms/master/protocol/openid-connect/token`
|
||||
|
||||
s = requests.Session()
|
||||
s.verify = "/home/jimmy/Develop/mosquitto-plugin/test/ca.pem"
|
||||
s.cert = ("/home/jimmy/Develop/keycloak/jimmy-client.pem", "/home/jimmy/Develop/keycloak/jimmy-client-key.pem")
|
||||
|
||||
|
||||
# Get urls.
|
||||
print("Before get.")
|
||||
well_known = s.get("https://nginx-test.internal.jpace121.net:8443/realms/jpace121-main/.well-known/openid-configuration", ).json()
|
||||
print("After get.")
|
||||
token_url = well_known['token_endpoint']
|
||||
# Override for now, url doesn't include port...
|
||||
token_url = "https://nginx-test.internal.jpace121.net:8443/realms/jpace121-main/protocol/openid-connect/token"
|
||||
# RESULT=`curl --cacert ./ca.pem --cert jimmy-client.pem --key jimmy-client-key.pem --data "grant_type=password&client_id=mqtt&username=jimmy&password=1234" https://nginx-test.internal.jpace121.net:8443/realms/jpace121-main/protocol/openid-connect/token`
|
||||
|
||||
|
||||
data = {"grant_type" : "password", "client_id" : "mqtt", "username" : "jimmy", "password": "1234"}
|
||||
|
||||
# Request token.
|
||||
r = s.post(token_url, data=data)
|
||||
token = r.json()['access_token']
|
||||
|
||||
client = paho.mqtt.client.Client(protocol=paho.mqtt.client.MQTTv5,
|
||||
transport="tcp")
|
||||
client.username_pw_set("jimmy", password=token)
|
||||
client.connect("localhost", port=8081)
|
||||
|
||||
print("Waiting on connection.")
|
||||
time.sleep(20)
|
||||
Reference in new issue
Block a user