Kurlyk
Toggle main menu visibility
Loading...
Searching...
No Matches
BearerTokenAuthProvider.hpp
Go to the documentation of this file.
1
#pragma once
2
#ifndef _KURLYK_HTTP_AUTH_BEARER_TOKEN_AUTH_PROVIDER_HPP_INCLUDED
3
#define _KURLYK_HTTP_AUTH_BEARER_TOKEN_AUTH_PROVIDER_HPP_INCLUDED
4
7
8
#include "
IAuthProvider.hpp
"
9
#include <string>
10
11
namespace
kurlyk
{
12
namespace
http {
13
namespace
auth {
14
17
class
BearerTokenAuthProvider
:
public
IAuthProvider
{
18
public
:
21
explicit
BearerTokenAuthProvider
(
const
std::string& token)
22
:
m_token
(token) {}
23
26
void
set_token
(
const
std::string& token) {
27
m_token
= token;
28
}
29
30
bool
authorize
(
HttpRequest
& request)
const override
{
31
if
(
m_token
.empty())
return
false
;
32
request.
headers
.erase(
"Authorization"
);
33
request.
headers
.emplace(
"Authorization"
,
"Bearer "
+
m_token
);
34
return
true
;
35
}
36
37
bool
authorize
(
Headers
& headers)
const override
{
38
if
(
m_token
.empty())
return
false
;
39
headers.erase(
"Authorization"
);
40
headers.emplace(
"Authorization"
,
"Bearer "
+
m_token
);
41
return
true
;
42
}
43
44
private
:
45
std::string
m_token
;
46
};
47
48
}
// namespace auth
49
}
// namespace http
50
}
// namespace kurlyk
51
52
#endif
// _KURLYK_HTTP_AUTH_BEARER_TOKEN_AUTH_PROVIDER_HPP_INCLUDED
IAuthProvider.hpp
Defines the IAuthProvider interface for HTTP authentication strategies.
kurlyk::HttpRequest
Represents an HTTP request configuration.
Definition
HttpRequest.hpp:16
kurlyk::HttpRequest::headers
Headers headers
HTTP request headers.
Definition
HttpRequest.hpp:20
kurlyk::http::auth::BearerTokenAuthProvider::set_token
void set_token(const std::string &token)
Sets a new Bearer token, replacing any previous value.
Definition
BearerTokenAuthProvider.hpp:26
kurlyk::http::auth::BearerTokenAuthProvider::BearerTokenAuthProvider
BearerTokenAuthProvider(const std::string &token)
Constructs a provider with a Bearer token.
Definition
BearerTokenAuthProvider.hpp:21
kurlyk::http::auth::BearerTokenAuthProvider::m_token
std::string m_token
Definition
BearerTokenAuthProvider.hpp:45
kurlyk::http::auth::BearerTokenAuthProvider::authorize
bool authorize(HttpRequest &request) const override
Modifies an HttpRequest in-place to include authentication credentials.
Definition
BearerTokenAuthProvider.hpp:30
kurlyk::http::auth::BearerTokenAuthProvider::authorize
bool authorize(Headers &headers) const override
Modifies a header map in-place to include authentication credentials.
Definition
BearerTokenAuthProvider.hpp:37
kurlyk::http::auth::IAuthProvider
Interface for authentication providers that modify HTTP requests or headers.
Definition
IAuthProvider.hpp:17
kurlyk
Primary namespace for the Kurlyk library, encompassing initialization, request management,...
kurlyk::Headers
utils::CaseInsensitiveMultimap Headers
Alias for HTTP headers, providing a case-insensitive unordered multimap.
Definition
CaseInsensitiveMultimap.hpp:62
include
kurlyk
http
auth
BearerTokenAuthProvider.hpp
Generated by
1.17.0