Updated README.md and completed verification process

This commit is contained in:
kdeng00
2019-09-20 20:56:24 -04:00
parent 8ee39e13c0
commit 89ed9f9252
4 changed files with 80 additions and 70 deletions
+27 -19
View File
@@ -14,16 +14,10 @@ One can interface with Icarus the music server either by:
## Built With ## Built With
* C#
* [.NET Core](https://dotnet.microsoft.com/) 2.2
* .NET Web RESTful API
* C++ >= C++17 * C++ >= C++17
* GCC >= 8.0 * GCC >= 8.0
* conan
* [json](https://www.github.com/nlohmann/json) * [json](https://www.github.com/nlohmann/json)
* [cpr](https://www.github.com/whoshuu/cpr) * [cpr](https://www.github.com/whoshuu/cpr)
* [MySql](https://www.nuget.org/packages/MySql.Data/)
* [Newtonsoft.Json](https://www.newtonsoft.com/json)
* [TagLib](https://github.com/taglib/taglib) * [TagLib](https://github.com/taglib/taglib)
![image](https://user-images.githubusercontent.com/14333136/56252069-28532d00-6084-11e9-896d-1a3c378014ef.png) ![image](https://user-images.githubusercontent.com/14333136/56252069-28532d00-6084-11e9-896d-1a3c378014ef.png)
@@ -79,30 +73,34 @@ From the Application page, copy the client id and client secret. These values wi
<h1 align="center"> <h1 align="center">
<img src="Images/Configuration/api_cred.png" width=100%> <img src="Images/Configuration/api_cred.png" width=100%>
</h1> </h1>
Enter the information in the corresponding appsettings json file Enter the information in the corresponding ``authcredentials.json`` file
```Json ```Json
"Auth0": { {
"ClientId":"", "domain": "somedomain.auth0.com",
"ClientSecret":"" "api_identifier": "https://squawk/api"
}, "client_id": "clientidhere",
"client_secret": "illkeepyoumydirtylittlesecret"
}
``` ```
### API filesystem paths ### API filesystem paths
For the purposes of properly uploading, downloading, updating, deleting, and streaming songs the API filesystem paths must be configured. What is meant by this is that the `RootMusicPath` directory where all music will be stored must exist as well as the `ArchivePath` and `TemporaryMusicPath` paths. An example on a Linux system: For the purposes of properly uploading, downloading, updating, deleting, and streaming songs the API filesystem paths must be configured. For that purpose you have to open the ``paths.json`` file. What is meant by this is that the `root_music_path` directory where all music will be stored must exist. The `cover_root_path`, `archive_root_path`, and `temp_root_path` paths must exist and be accessible. An example on a Linux system:
```Json ```Json
{ {
"RootMusicPath": "/home/dev/null/music/", "root_music_path": "/home/dev/null/music/",
"TemporaryMusicPath": "/home/dev/null/music/temp/", "temp_root_path": "/home/dev/null/music/temp/",
"ArchivePath": "/home/dev/null/music/archive/" "cover_root_path": "/home/dev/null/music/coverArt/",
"archive_root_path": "/home/dev/null/music/archive/"
} }
``` ```
* RootMusicPath - Where music will be stored in the following convention: *`Artist/Album/Songs`* * `root_music_path` - Where music will be stored in the following convention: *`Artist/Album/Songs`*
* TemporaryMusicPath - Where music will be stored when uploding songs to the server until the metadata has been fully parsed and entered into the database. Upon completion the files will be deleted and moved to the appropriate path in the `RootMusicPath` * `temp_music_path` - Where music will be stored when uploding songs to the server until the metadata has been fully parsed and entered into the database. Upon completion the files will be deleted and moved to the appropriate path in the `root_music_path`
* ArchivePath - When downloading compressed songs this is the path where songs will be compressed prior to dataa being read into memory, deleting the compressed file, and sending the compressed file from memory to the client * `cover_root_path` - Where cover art of music will be saved to.
* `archive_root_path` - When downloading compressed songs this is the path where songs will be compressed prior to dataa being read into memory, deleting the compressed file, and sending the compressed file from memory to the client
**Note**: The `TemporaryMusic` or `ArchivePath` does not have to be located in the `RootMusicPath`. Ensure that the permissions are properly set for all of the paths. **Note**: The `temp_root_path`, `cover_root_path`, or `archive_root_path` does not have to be located in the same parent directory as `root_music_path`. Ensure that the permissions are properly set for all of the paths.
### Database connection string ### Database connection string
@@ -149,6 +147,16 @@ From this point the database has been successfully configured. Metadata and song
<sup>*</sup> Will only need to execute this for UserContext and SongContext because the Song table has relational constraints with Album, Artist, Year, and Genre. <sup>*</sup> Will only need to execute this for UserContext and SongContext because the Song table has relational constraints with Album, Artist, Year, and Genre.
## Building and Running
```
git clone --recursive https://github.com/kdeng00/icarus
mkdir build
cd build
cmake ..
bin/icarus
```
Runs the server on localhost port 5002
## Contributing ## Contributing
Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on the code of conduct, and the process for submitting pull requests to the project. Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on the code of conduct, and the process for submitting pull requests to the project.
+7 -2
View File
@@ -6,7 +6,9 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include <cpr/cpr.h>
#include <jwt-cpp/jwt.h> #include <jwt-cpp/jwt.h>
#include <nlohmann/json.hpp>
#include "model/Models.h" #include "model/Models.h"
#include "type/Scopes.h" #include "type/Scopes.h"
@@ -18,12 +20,15 @@ namespace manager
public: public:
TokenManager(); TokenManager();
model::LoginResult retrieveToken();
model::LoginResult retrieveToken(std::string_view);
model::LoginResult retrieveToken(const model::BinaryPath&); model::LoginResult retrieveToken(const model::BinaryPath&);
bool isTokenValid(std::string&, type::Scope); bool isTokenValid(std::string&, type::Scope);
bool testAuth(const model::BinaryPath&);
private: private:
cpr::Response sendRequest(std::string_view, nlohmann::json&);
nlohmann::json createTokenBody(const model::AuthCredentials&);
model::AuthCredentials parseAuthCredentials(std::string_view); model::AuthCredentials parseAuthCredentials(std::string_view);
model::AuthCredentials parseAuthCredentials(const model::BinaryPath&); model::AuthCredentials parseAuthCredentials(const model::BinaryPath&);
+42 -47
View File
@@ -9,9 +9,6 @@
#include <sstream> #include <sstream>
#include <cstdlib> #include <cstdlib>
#include <cpr/cpr.h>
#include <nlohmann/json.hpp>
#include "manager/DirectoryManager.h" #include "manager/DirectoryManager.h"
namespace fs = std::filesystem; namespace fs = std::filesystem;
@@ -21,51 +18,12 @@ manager::TokenManager::TokenManager()
{ {
} }
model::LoginResult manager::TokenManager::retrieveToken()
{
model::LoginResult lr;
lr.accessToken = "dsfdsf";
lr.tokenType = "demo";
return lr;
}
model::LoginResult manager::TokenManager::retrieveToken(std::string_view path)
{
auto cred = parseAuthCredentials(path);
nlohmann::json reqObj;
reqObj["client_id"] = cred.clientId;
reqObj["client_secret"] = cred.clientSecret;
reqObj["audience"] = cred.apiIdentifier;
reqObj["grant_type"] = "client_credentials";
std::string uri{cred.uri};
uri.append("/");
uri.append(cred.endpoint);
auto r = cpr::Post(cpr::Url{uri},
cpr::Body{reqObj.dump()},
cpr::Header{{"Content-Type", "application/json"},
{"Connection", "keep-alive"}});
auto postRes = nlohmann::json::parse(r.text);
model::LoginResult lr;
lr.accessToken = postRes["access_token"].get<std::string>();
lr.tokenType = postRes["token_type"].get<std::string>();
lr.expiration = postRes["expires_in"].get<int>();
return lr;
}
model::LoginResult manager::TokenManager::retrieveToken(const model::BinaryPath& bConf) model::LoginResult manager::TokenManager::retrieveToken(const model::BinaryPath& bConf)
{ {
auto cred = parseAuthCredentials(bConf); auto cred = parseAuthCredentials(bConf);
nlohmann::json reqObj; auto reqObj = createTokenBody(cred);
reqObj["client_id"] = cred.clientId;
reqObj["client_secret"] = cred.clientSecret;
reqObj["audience"] = cred.apiIdentifier;
reqObj["grant_type"] = "client_credentials";
std::string uri{cred.uri}; std::string uri{cred.uri};
uri.append("/"); uri.append("/");
@@ -76,6 +34,7 @@ model::LoginResult manager::TokenManager::retrieveToken(const model::BinaryPath&
cpr::Header{{"Content-Type", "application/json"}, cpr::Header{{"Content-Type", "application/json"},
{"Connection", "keep-alive"}}); {"Connection", "keep-alive"}});
auto postRes = nlohmann::json::parse(r.text); auto postRes = nlohmann::json::parse(r.text);
model::LoginResult lr; model::LoginResult lr;
@@ -86,6 +45,7 @@ model::LoginResult manager::TokenManager::retrieveToken(const model::BinaryPath&
return lr; return lr;
} }
bool manager::TokenManager::isTokenValid(std::string& auth, type::Scope scope) bool manager::TokenManager::isTokenValid(std::string& auth, type::Scope scope)
{ {
auto authPair = fetchAuthHeader(auth); auto authPair = fetchAuthHeader(auth);
@@ -115,6 +75,43 @@ bool manager::TokenManager::isTokenValid(std::string& auth, type::Scope scope)
return false; return false;
} }
bool manager::TokenManager::testAuth(const model::BinaryPath& bConf)
{
auto cred = parseAuthCredentials(bConf);
auto reqObj = createTokenBody(cred);
std::string uri(cred.uri);
uri.append("/");
uri.append(cred.endpoint);
auto response = sendRequest(uri, reqObj);
return (response.status_code == 200) ? true : false;
}
cpr::Response manager::TokenManager::sendRequest(std::string_view uri, nlohmann::json& obj)
{
auto resp = cpr::Post(cpr::Url{uri}, cpr::Body{obj.dump()},
cpr::Header{{"Content-type", "application/json"},
{"Connection", "keep-alive"}});
return resp;
}
nlohmann::json manager::TokenManager::createTokenBody(const model::AuthCredentials& auth)
{
nlohmann::json obj;
obj["client_id"] = auth.clientId;
obj["client_secret"] = auth.clientSecret;
obj["audience"] = auth.apiIdentifier;
obj["grant_type"] = "client_credentials";
return obj;
}
model::AuthCredentials manager::TokenManager::parseAuthCredentials(std::string_view path) model::AuthCredentials manager::TokenManager::parseAuthCredentials(std::string_view path)
{ {
auto exe_path = manager::DirectoryManager::configPath(path); auto exe_path = manager::DirectoryManager::configPath(path);
@@ -134,10 +131,7 @@ model::AuthCredentials manager::TokenManager::parseAuthCredentials(std::string_v
} }
model::AuthCredentials manager::TokenManager::parseAuthCredentials(const model::BinaryPath& bConf) model::AuthCredentials manager::TokenManager::parseAuthCredentials(const model::BinaryPath& bConf)
{ {
auto exePath = manager::DirectoryManager::configPath(bConf); auto con = manager::DirectoryManager::credentialConfigContent(bConf);
exePath.append("/authcredentials.json");
auto con = manager::DirectoryManager::credentialConfigContent(exePath);
model::AuthCredentials auth; model::AuthCredentials auth;
auth.uri = "https://"; auth.uri = "https://";
@@ -187,6 +181,7 @@ std::pair<bool, std::vector<std::string>> manager::TokenManager::fetchAuthHeader
return std::make_pair(foundBearer, authHeader); return std::make_pair(foundBearer, authHeader);
} }
bool manager::TokenManager::tokenSupportsScope(const std::vector<std::string> scopes, const std::string&& scope) bool manager::TokenManager::tokenSupportsScope(const std::vector<std::string> scopes, const std::string&& scope)
{ {
return std::any_of(scopes.begin(), scopes.end(), return std::any_of(scopes.begin(), scopes.end(),
+4 -2
View File
@@ -5,6 +5,7 @@
#include "database/BaseRepository.h" #include "database/BaseRepository.h"
#include "manager/DirectoryManager.h" #include "manager/DirectoryManager.h"
#include "manager/TokenManager.h"
#include "type/PathType.h" #include "type/PathType.h"
namespace fs = std::filesystem; namespace fs = std::filesystem;
@@ -27,8 +28,9 @@ void verify::Initialization::checkIcarus(const model::BinaryPath& bConf)
// verifies that the authorization settings are not the default values // verifies that the authorization settings are not the default values
bool verify::Initialization::confirmConfigAuth(const model::BinaryPath& bConf) bool verify::Initialization::confirmConfigAuth(const model::BinaryPath& bConf)
{ {
auto authConfig = manager::DirectoryManager::credentialConfigContent(bConf); manager::TokenManager tokMgr;
return true;
return tokMgr.testAuth(bConf);
} }
// verifies if database connectivity can be established // verifies if database connectivity can be established