lluserauth.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**
  2. * @file lluserauth.h
  3. * @brief LLUserAuth class header file
  4. *
  5. * $LicenseInfo:firstyear=2003&license=viewergpl$
  6. *
  7. * Copyright (c) 2003-2009, Linden Research, Inc.
  8. * Copyright (c) 2009-2024, Henri Beauchamp.
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #ifndef LLUSERAUTH_H
  34. #define LLUSERAUTH_H
  35. #include <map>
  36. #include <string>
  37. #include <vector>
  38. class LLXMLRPCTransaction;
  39. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  40. // This class encapsulates the authentication and initialization from the login
  41. // server. Construct an instance of this object, and call the authenticate()
  42. // method, and call authResponse() until it returns a non-negative value. If
  43. // that method returns E_OK, you can start asking for responses via the
  44. // getResponse*() methods.
  45. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  46. class LLUserAuth
  47. {
  48. protected:
  49. LOG_CLASS(LLUserAuth);
  50. public:
  51. LLUserAuth();
  52. ~LLUserAuth();
  53. // These codes map to the curl return codes...
  54. typedef enum {
  55. E_NO_RESPONSE_YET = -2,
  56. E_DOWNLOADING = -1,
  57. E_OK = 0,
  58. E_COULDNT_RESOLVE_HOST,
  59. E_SSL_PEER_CERTIFICATE,
  60. E_SSL_CACERT,
  61. E_SSL_CONNECT_ERROR,
  62. E_UNHANDLED_ERROR,
  63. E_LAST // Never use this !
  64. } UserAuthcode;
  65. // Clears out internal data cache.
  66. void reset();
  67. // Used in llappviewer.cpp to transmit all the constant data to us. HB
  68. void init(const std::string& platform_ver, const std::string& os_string,
  69. const std::string& viewer_version, const std::string& channel,
  70. const std::string& serial_hash, const std::string& mac_hash);
  71. // Used in llstartup.cpp to transmit the MFA token and MFA hash prior to
  72. // authentication. HB
  73. void setMFA(bool use_mfa, const std::string& mfa_hash,
  74. const std::string& mfa_token);
  75. void authenticate(const std::string& auth_uri,
  76. const std::string& auth_method,
  77. const std::string& firstname,
  78. const std::string& lastname,
  79. const std::string& password,
  80. const std::string& start,
  81. bool skip_optional_update, bool accept_tos,
  82. bool accept_critical_message,
  83. S32 last_exec_event,
  84. const std::vector<const char*>& requested_options);
  85. UserAuthcode authResponse();
  86. LL_INLINE const std::string& errorMessage() const
  87. {
  88. return mErrorMessage;
  89. }
  90. LL_INLINE const LLSD& getResponse() const { return mResponses; }
  91. // Method to get a direct reponse from the login API by name.
  92. LL_INLINE const LLSD& getResponse(const std::string& name) const
  93. {
  94. return mResponses[name];
  95. }
  96. LL_INLINE std::string getResponseStr(const std::string& name) const
  97. {
  98. return mResponses.has(name) ? mResponses[name].asString() : "";
  99. }
  100. // Returns the mResponses[name][0] LLSD map when it exists. HB
  101. const LLSD& getResponse1stMap(const std::string& name) const;
  102. private:
  103. LLXMLRPCTransaction* mTransaction;
  104. std::string mPlatformVersion;
  105. std::string mPlatformOSString;
  106. std::string mViewerVersion;
  107. std::string mViewerChannel;
  108. std::string mHashedSerial;
  109. std::string mHashedMAC;
  110. std::string mMFAHash;
  111. std::string mMFAToken;
  112. std::string mErrorMessage;
  113. std::string mIndentation;
  114. LLSD mResponses;
  115. UserAuthcode mAuthResponse;
  116. bool mUseMFA;
  117. };
  118. extern LLUserAuth gUserAuth;
  119. #endif // LLUSERAUTH_H