mirror of
https://github.com/jpace121/j7s-jwt-mosquitto-auth.git
synced 2026-11-03 15:27:46 +00:00
Pass device grant test.
This commit is contained in:
1 parent
3b4be67de3
commit
fa238f650d
3 files changed
+12
-4
No files matched your search
+2
-1
@@ -25,7 +25,7 @@ std::optional<std::string> getKey(const std::string &user, const YAML::Node &key
|
|||||||
|
|
||||||
// Class implementation.
|
// Class implementation.
|
||||||
Authorizer::Authorizer(const std::string &keyFilePath, const std::string &aclFilePath) :
|
Authorizer::Authorizer(const std::string &keyFilePath, const std::string &aclFilePath) :
|
||||||
_keyFile{keyFilePath}, _aclFile{aclFilePath}
|
_keyFile{YAML::LoadFile(keyFilePath)}, _aclFile{YAML::LoadFile(aclFilePath)}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,6 +98,7 @@ bool Authorizer::is_unknown(const std::string &username)
|
|||||||
std::tuple<bool, bool> checkACL(const std::string &user, const YAML::Node &aclFile)
|
std::tuple<bool, bool> checkACL(const std::string &user, const YAML::Node &aclFile)
|
||||||
{
|
{
|
||||||
// TODO: Make sure default exists.
|
// TODO: Make sure default exists.
|
||||||
|
|
||||||
YAML::Node userDict;
|
YAML::Node userDict;
|
||||||
if (aclFile[user])
|
if (aclFile[user])
|
||||||
{
|
{
|
||||||
|
|||||||
+10
-2
@@ -61,6 +61,8 @@ bool validate(const std::string &token, const std::string &username, const std::
|
|||||||
}
|
}
|
||||||
auto claims = decoded_token.get_payload_claims();
|
auto claims = decoded_token.get_payload_claims();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
// Check username matches.
|
// Check username matches.
|
||||||
if (not claims.contains("upn"))
|
if (not claims.contains("upn"))
|
||||||
{
|
{
|
||||||
@@ -79,7 +81,7 @@ bool validate(const std::string &token, const std::string &username, const std::
|
|||||||
std::cerr << "Missing mqtt claim." << std::endl;
|
std::cerr << "Missing mqtt claim." << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (not(claims["mqtt"].as_string() == "true"))
|
if (not(claims["mqtt"].as_bool()))
|
||||||
{
|
{
|
||||||
std::cerr << "Not claiming can do mqtt." << std::endl;
|
std::cerr << "Not claiming can do mqtt." << std::endl;
|
||||||
return false;
|
return false;
|
||||||
@@ -91,6 +93,12 @@ bool validate(const std::string &token, const std::string &username, const std::
|
|||||||
std::cerr << "Missing expiration time claim." << std::endl;
|
std::cerr << "Missing expiration time claim." << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch(const std::bad_cast& exception)
|
||||||
|
{
|
||||||
|
std::cerr << "Failed to parse claims. Reason: " << exception.what() << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -105,7 +113,7 @@ std::string gen_token(
|
|||||||
const auto token = jwt::create()
|
const auto token = jwt::create()
|
||||||
.set_type("JWT")
|
.set_type("JWT")
|
||||||
.set_payload_claim("upn", jwt::claim(username))
|
.set_payload_claim("upn", jwt::claim(username))
|
||||||
.set_payload_claim("mqtt", jwt::claim(std::string("true")))
|
.set_payload_claim("mqtt", jwt::claim(picojson::value(true)))
|
||||||
.set_issued_at(issue_time)
|
.set_issued_at(issue_time)
|
||||||
.set_expires_at(expr_time)
|
.set_expires_at(expr_time)
|
||||||
.sign(jwt::algorithm::rs256(pub_key, priv_key, "", ""));
|
.sign(jwt::algorithm::rs256(pub_key, priv_key, "", ""));
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
#include <j7s-plugin/utils.h>
|
#include <j7s-plugin/utils.h>
|
||||||
|
|
||||||
#include <ctime>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|||||||
Reference in new issue
Block a user