Turi Create  4.0
authentication_token_method.hpp
1 /* Copyright © 2017 Apple Inc. All rights reserved.
2  *
3  * Use of this source code is governed by a BSD-3-clause license that can
4  * be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
5  */
6 #ifndef CPPIPC_COMMON_AUTHENTICATION_TOKEN_HPP
7 #define CPPIPC_COMMON_AUTHENTICATION_TOKEN_HPP
8 #include <string>
9 #include <core/system/cppipc/common/message_types.hpp>
10 #include <core/system/cppipc/common/authentication_base.hpp>
11 namespace cppipc {
12 /**
13  *
14  * The authentication token method is the simplest mode of authentication.
15  * Both client and server knows a secret token value, then every message
16  * between client and server must contain the token. Without additional
17  * safeguards, this authentication method does not provide any real security
18  * aside from protecting against accidental connections, since any packet
19  * sniffer will be able to obtain the token value.
20  */
22  private:
23  std::string token_value;
24  public:
25  authentication_token_method(std::string token_value) : token_value(token_value) { }
26  inline ~authentication_token_method(){}
27  inline void apply_auth(call_message& msg) {
28  msg.properties["authtoken"] = token_value;
29  }
30 
31  inline void apply_auth(reply_message& msg) {
32  msg.properties["authtoken"] = token_value;
33  }
34  inline bool validate_auth(call_message& msg) {
35  return msg.properties.count("authtoken") > 0 &&
36  msg.properties["authtoken"] == token_value;
37  }
38  inline bool validate_auth(reply_message& msg) {
39  return msg.properties.count("authtoken") > 0 &&
40  msg.properties["authtoken"] == token_value;
41  }
42 
43 };
44 
45 
46 
47 } // cppipc
48 #endif
std::map< std::string, std::string > properties
The status of the call.
std::map< std::string, std::string > properties
the function to call on the object