Updated README.md and completed verification process
This commit is contained in:
@@ -14,16 +14,10 @@ One can interface with Icarus the music server either by:
|
||||
## Built With
|
||||
|
||||
|
||||
* C#
|
||||
* [.NET Core](https://dotnet.microsoft.com/) 2.2
|
||||
* .NET Web RESTful API
|
||||
* C++ >= C++17
|
||||
* GCC >= 8.0
|
||||
* conan
|
||||
* [json](https://www.github.com/nlohmann/json)
|
||||
* [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)
|
||||
|
||||

|
||||
@@ -79,30 +73,34 @@ From the Application page, copy the client id and client secret. These values wi
|
||||
<h1 align="center">
|
||||
<img src="Images/Configuration/api_cred.png" width=100%>
|
||||
</h1>
|
||||
Enter the information in the corresponding appsettings json file
|
||||
Enter the information in the corresponding ``authcredentials.json`` file
|
||||
```Json
|
||||
"Auth0": {
|
||||
"ClientId":"",
|
||||
"ClientSecret":""
|
||||
},
|
||||
{
|
||||
"domain": "somedomain.auth0.com",
|
||||
"api_identifier": "https://squawk/api"
|
||||
"client_id": "clientidhere",
|
||||
"client_secret": "illkeepyoumydirtylittlesecret"
|
||||
}
|
||||
```
|
||||
|
||||
### 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
|
||||
{
|
||||
"RootMusicPath": "/home/dev/null/music/",
|
||||
"TemporaryMusicPath": "/home/dev/null/music/temp/",
|
||||
"ArchivePath": "/home/dev/null/music/archive/"
|
||||
"root_music_path": "/home/dev/null/music/",
|
||||
"temp_root_path": "/home/dev/null/music/temp/",
|
||||
"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`*
|
||||
* 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`
|
||||
* 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
|
||||
* `root_music_path` - Where music will be stored in the following convention: *`Artist/Album/Songs`*
|
||||
* `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`
|
||||
* `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
|
||||
|
||||
@@ -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.
|
||||
|
||||
## 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
|
||||
|
||||
Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on the code of conduct, and the process for submitting pull requests to the project.
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <cpr/cpr.h>
|
||||
#include <jwt-cpp/jwt.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "model/Models.h"
|
||||
#include "type/Scopes.h"
|
||||
@@ -18,12 +20,15 @@ namespace manager
|
||||
public:
|
||||
TokenManager();
|
||||
|
||||
model::LoginResult retrieveToken();
|
||||
model::LoginResult retrieveToken(std::string_view);
|
||||
model::LoginResult retrieveToken(const model::BinaryPath&);
|
||||
|
||||
bool isTokenValid(std::string&, type::Scope);
|
||||
bool testAuth(const model::BinaryPath&);
|
||||
private:
|
||||
cpr::Response sendRequest(std::string_view, nlohmann::json&);
|
||||
|
||||
nlohmann::json createTokenBody(const model::AuthCredentials&);
|
||||
|
||||
model::AuthCredentials parseAuthCredentials(std::string_view);
|
||||
model::AuthCredentials parseAuthCredentials(const model::BinaryPath&);
|
||||
|
||||
|
||||
@@ -9,9 +9,6 @@
|
||||
#include <sstream>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <cpr/cpr.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "manager/DirectoryManager.h"
|
||||
|
||||
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)
|
||||
{
|
||||
auto cred = parseAuthCredentials(bConf);
|
||||
|
||||
nlohmann::json reqObj;
|
||||
reqObj["client_id"] = cred.clientId;
|
||||
reqObj["client_secret"] = cred.clientSecret;
|
||||
reqObj["audience"] = cred.apiIdentifier;
|
||||
reqObj["grant_type"] = "client_credentials";
|
||||
auto reqObj = createTokenBody(cred);
|
||||
|
||||
std::string uri{cred.uri};
|
||||
uri.append("/");
|
||||
@@ -76,6 +34,7 @@ model::LoginResult manager::TokenManager::retrieveToken(const model::BinaryPath&
|
||||
cpr::Header{{"Content-Type", "application/json"},
|
||||
{"Connection", "keep-alive"}});
|
||||
|
||||
|
||||
auto postRes = nlohmann::json::parse(r.text);
|
||||
|
||||
model::LoginResult lr;
|
||||
@@ -86,6 +45,7 @@ model::LoginResult manager::TokenManager::retrieveToken(const model::BinaryPath&
|
||||
return lr;
|
||||
}
|
||||
|
||||
|
||||
bool manager::TokenManager::isTokenValid(std::string& auth, type::Scope scope)
|
||||
{
|
||||
auto authPair = fetchAuthHeader(auth);
|
||||
@@ -115,6 +75,43 @@ bool manager::TokenManager::isTokenValid(std::string& auth, type::Scope scope)
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
auto exePath = manager::DirectoryManager::configPath(bConf);
|
||||
exePath.append("/authcredentials.json");
|
||||
|
||||
auto con = manager::DirectoryManager::credentialConfigContent(exePath);
|
||||
auto con = manager::DirectoryManager::credentialConfigContent(bConf);
|
||||
|
||||
model::AuthCredentials auth;
|
||||
auth.uri = "https://";
|
||||
@@ -187,6 +181,7 @@ std::pair<bool, std::vector<std::string>> manager::TokenManager::fetchAuthHeader
|
||||
return std::make_pair(foundBearer, authHeader);
|
||||
}
|
||||
|
||||
|
||||
bool manager::TokenManager::tokenSupportsScope(const std::vector<std::string> scopes, const std::string&& scope)
|
||||
{
|
||||
return std::any_of(scopes.begin(), scopes.end(),
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "database/BaseRepository.h"
|
||||
#include "manager/DirectoryManager.h"
|
||||
#include "manager/TokenManager.h"
|
||||
#include "type/PathType.h"
|
||||
|
||||
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
|
||||
bool verify::Initialization::confirmConfigAuth(const model::BinaryPath& bConf)
|
||||
{
|
||||
auto authConfig = manager::DirectoryManager::credentialConfigContent(bConf);
|
||||
return true;
|
||||
manager::TokenManager tokMgr;
|
||||
|
||||
return tokMgr.testAuth(bConf);
|
||||
}
|
||||
|
||||
// verifies if database connectivity can be established
|
||||
|
||||
Reference in New Issue
Block a user