blob: 392115ad5f7345d6a917b15c69d29c0f377848a7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
//
// OAuth20Credentials.cpp
//
// Library: Net
// Package: OAuth
// Module: OAuth20Credentials
//
// Copyright (c) 2014, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Net/OAuth20Credentials.h"
#include "Poco/Net/HTTPRequest.h"
#include "Poco/Net/NetException.h"
#include "Poco/String.h"
namespace Poco {
namespace Net {
const std::string OAuth20Credentials::SCHEME = "Bearer";
OAuth20Credentials::OAuth20Credentials():
_scheme(SCHEME)
{
}
OAuth20Credentials::OAuth20Credentials(const std::string& bearerToken):
_bearerToken(bearerToken),
_scheme(SCHEME)
{
}
OAuth20Credentials::OAuth20Credentials(const std::string& bearerToken, const std::string& scheme):
_bearerToken(bearerToken),
_scheme(scheme)
{
}
OAuth20Credentials::OAuth20Credentials(const HTTPRequest& request):
_scheme(SCHEME)
{
extractBearerToken(request);
}
OAuth20Credentials::OAuth20Credentials(const HTTPRequest& request, const std::string& scheme):
_scheme(scheme)
{
extractBearerToken(request);
}
OAuth20Credentials::~OAuth20Credentials()
{
}
void OAuth20Credentials::setBearerToken(const std::string& bearerToken)
{
_bearerToken = bearerToken;
}
void OAuth20Credentials::setScheme(const std::string& scheme)
{
_scheme = scheme;
}
void OAuth20Credentials::authenticate(HTTPRequest& request)
{
std::string auth(_scheme);
auth += ' ';
auth += _bearerToken;
request.set(HTTPRequest::AUTHORIZATION, auth);
}
void OAuth20Credentials::extractBearerToken(const HTTPRequest& request)
{
if (request.hasCredentials())
{
std::string authScheme;
std::string authInfo;
request.getCredentials(authScheme, authInfo);
if (icompare(authScheme, _scheme) == 0)
{
_bearerToken = authInfo;
}
else throw NotAuthenticatedException("No bearer token in Authorization header", authScheme);
}
else throw NotAuthenticatedException("No Authorization header found");
}
} } // namespace Poco::Net
|