2018-11-22 05:03:42 -06:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// WOPI Authorization
|
|
|
|
|
2020-04-18 03:39:50 -05:00
|
|
|
#pragma once
|
2018-11-22 05:03:42 -06:00
|
|
|
|
|
|
|
#include <string>
|
2022-03-28 09:51:38 -05:00
|
|
|
#include <vector>
|
2018-11-22 05:03:42 -06:00
|
|
|
|
2022-03-28 09:51:38 -05:00
|
|
|
namespace Poco
|
|
|
|
{
|
|
|
|
namespace Net
|
|
|
|
{
|
|
|
|
class HTTPRequest;
|
|
|
|
}
|
|
|
|
|
|
|
|
class URI;
|
|
|
|
|
|
|
|
} // namespace Poco
|
2018-11-22 05:03:42 -06:00
|
|
|
|
2020-07-02 03:15:20 -05:00
|
|
|
/// Class to keep the authorization data, which can be either access_token or access_header.
|
2018-11-22 05:03:42 -06:00
|
|
|
class Authorization
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum class Type
|
|
|
|
{
|
2022-11-22 20:21:21 -06:00
|
|
|
None, //< Unlike Expired, this implies no Authorization needed.
|
2018-11-22 05:03:42 -06:00
|
|
|
Token,
|
2022-11-22 20:21:21 -06:00
|
|
|
Header,
|
|
|
|
Expired //< The server is rejecting the current authorization key.
|
2018-11-22 05:03:42 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2022-05-05 17:17:38 -05:00
|
|
|
Type _type;
|
|
|
|
std::string _data;
|
2018-11-22 05:03:42 -06:00
|
|
|
|
|
|
|
public:
|
|
|
|
Authorization()
|
|
|
|
: _type(Type::None)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Authorization(Type type, const std::string& data)
|
|
|
|
: _type(type)
|
|
|
|
, _data(data)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-06-20 13:09:21 -05:00
|
|
|
/// Create an Authorization instance from the URI query parameters.
|
|
|
|
/// Expects access_token (preferred) or access_header.
|
2022-03-28 09:51:38 -05:00
|
|
|
static Authorization create(const Poco::URI& uri);
|
|
|
|
static Authorization create(const std::string& uri);
|
2020-06-20 13:09:21 -05:00
|
|
|
|
2022-05-05 17:17:38 -05:00
|
|
|
void resetAccessToken(std::string accessToken)
|
|
|
|
{
|
|
|
|
_type = Type::Token;
|
|
|
|
_data = std::move(accessToken);
|
|
|
|
}
|
|
|
|
|
2022-11-22 20:21:21 -06:00
|
|
|
/// Expire the Authorization data.
|
|
|
|
void expire() { _type = Type::Expired; }
|
|
|
|
|
|
|
|
/// Returns true iff the Authorization data is invalid.
|
|
|
|
bool isExpired() const { return _type == Type::Expired; }
|
|
|
|
|
2022-08-22 15:00:05 -05:00
|
|
|
/// Set the access_token parameter to the given URI.
|
2018-11-22 05:03:42 -06:00
|
|
|
void authorizeURI(Poco::URI& uri) const;
|
|
|
|
|
|
|
|
/// Set the Authorization: header in request.
|
|
|
|
void authorizeRequest(Poco::Net::HTTPRequest& request) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|