diff --git a/src/controller/songController.hpp b/src/controller/songController.hpp index 82d26e7..d7f7db2 100644 --- a/src/controller/songController.hpp +++ b/src/controller/songController.hpp @@ -38,7 +38,7 @@ public: auto auth = authHeader->std_str(); - std::cout << "auth " << auth << std::endl; + //std::cout << "auth " << auth << std::endl; token_manager tok; if (!tok.is_token_valid(auth, Scope::upload)) { diff --git a/src/token_manager.cpp b/src/token_manager.cpp index c8c4299..22b434c 100644 --- a/src/token_manager.cpp +++ b/src/token_manager.cpp @@ -1,12 +1,15 @@ #include +#include #include #include #include #include #include +#include #include #include +#include #include #include "token_manager.h" @@ -57,6 +60,54 @@ loginResult token_manager::retrieve_token(std::string_view path) bool token_manager::is_token_valid(std::string& auth, Scope scope) { + std::istringstream iss(auth); + std::vector authHeader{std::istream_iterator(iss), + std::istream_iterator() + }; + + auto wordCount = 0; + /** + for (auto& word : authHeader) { + std::cout << "word " << wordCount++ << " " << word << std::endl; + } + */ + + if (!std::any_of(authHeader.begin(), authHeader.end(), [](std::string word) + { + std::cout << "comparing " << word << " to Bearer" << std::endl; + return (word.compare("Bearer") == 0); + })) { + std::cout << "Bearer not found" << std::endl; + return false; + } + + auto token = authHeader.at(authHeader.size()-1); + std::cout << "going to decode " << token << std::endl; + auto decoded = jwt::decode(token); + + std::vector scopes; + for (auto d : decoded.get_payload_claims()) { + if (d.first.compare("scope") == 0) { + std::cout << "found scope" << std::endl; + std::string all_scopes(d.second.to_json().get()); + std::istringstream iss(all_scopes); + + scopes.assign(std::istream_iterator(iss), + std::istream_iterator()); + //std::cout << scopes << std::endl; + } + } + + std::cout << "printing all scopes" << std::endl; + + for (auto& scope_obj : scopes) { + std::cout << scope_obj << std::endl; + } + + + std::cout << "goodbye" << std::endl; + exit(1); + switch (scope) { case Scope::upload: break;