api_auth.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #pragma once
  2. #include <bfc/dispatch.h>
  3. #include <time.h>
  4. class ifc_authcallback;
  5. enum
  6. {
  7. AUTHPARAM_EMPTY = 0,
  8. AUTHPARAM_TOOSHORT = 1,
  9. AUTHPARAM_TOOLONG = 2,
  10. AUTHPARAM_BADFORMAT = 3,
  11. };
  12. enum
  13. {
  14. AUTH_SUCCESS = 0,
  15. AUTH_404 = 1,
  16. AUTH_TIMEOUT = 2,
  17. AUTH_NOHTTP = 3,
  18. AUTH_NOPARSER = 4,
  19. AUTH_CONNECTIONRESET = 5,
  20. AUTH_ERROR_PARSING_XML = 6,
  21. AUTH_NOT_AUTHORIZED = 7,
  22. AUTH_SECURID = 8,
  23. AUTH_ABORT = 10,
  24. AUTH_INVALIDCRED = 11,
  25. AUTH_UNCONFIRMED = 12,
  26. AUTH_UNEXPECTED = 13, // unexpected catastrophic failure
  27. AUTH_INVALIDPASSCODE = 14,
  28. AUTH_USERNAME = 20,
  29. AUTH_USERNAME_EMPTY = (AUTH_USERNAME + AUTHPARAM_EMPTY),
  30. AUTH_USERNAME_TOOSHORT = (AUTH_USERNAME + AUTHPARAM_TOOSHORT),
  31. AUTH_USERNAME_TOOLONG = (AUTH_USERNAME + AUTHPARAM_TOOLONG),
  32. AUTH_USERNAME_BADFORMAT = (AUTH_USERNAME + AUTHPARAM_BADFORMAT),
  33. AUTH_PASSWORD = 30,
  34. AUTH_PASSWORD_EMPTY = (AUTH_PASSWORD + AUTHPARAM_EMPTY),
  35. AUTH_PASSWORD_TOOSHORT = (AUTH_PASSWORD + AUTHPARAM_TOOSHORT),
  36. AUTH_PASSWORD_TOOLONG = (AUTH_PASSWORD + AUTHPARAM_TOOLONG),
  37. AUTH_PASSWORD_BADFORMAT = (AUTH_PASSWORD + AUTHPARAM_BADFORMAT),
  38. AUTH_PASSCODE = 40,
  39. AUTH_PASSCODE_EMPTY = (AUTH_PASSCODE + AUTHPARAM_EMPTY),
  40. AUTH_PASSCODE_TOOSHORT = (AUTH_PASSCODE + AUTHPARAM_TOOSHORT),
  41. AUTH_PASSCODE_TOOLONG = (AUTH_PASSCODE + AUTHPARAM_TOOLONG),
  42. AUTH_PASSCODE_BADFORMAT = (AUTH_PASSCODE + AUTHPARAM_BADFORMAT),
  43. };
  44. // {392839D2-640D-4961-8E2A-1B5315C2F970}
  45. static const GUID AuthApiGUID =
  46. { 0x392839d2, 0x640d, 0x4961, { 0x8e, 0x2a, 0x1b, 0x53, 0x15, 0xc2, 0xf9, 0x70 } };
  47. class api_auth : public Dispatchable
  48. {
  49. protected:
  50. api_auth() {}
  51. ~api_auth() {}
  52. public:
  53. struct AuthResults
  54. {
  55. // plx2b using SecureZeroMemory when you are done :)
  56. char session_key[256]; // seems to be strlen = ~200, but let's just be safe
  57. char token[256]; // always seems to be strlen=44, but let's just be safe
  58. __time64_t expire; // expiration time in absolute time [AOL's Auth API returns duration, but api_auth adds time()]
  59. char context[512]; // dunno exact length yet
  60. int statusCode;
  61. int statusDetailCode;
  62. };
  63. static const GUID getServiceGuid() { return AuthApiGUID; }
  64. int Login(const wchar_t *username, const wchar_t *password, AuthResults *results, ifc_authcallback *callback);
  65. int LoginSecurID(const wchar_t *username, const wchar_t *password, const char *context, const wchar_t *securid, AuthResults *results, ifc_authcallback *callback);
  66. // realm is just a "named account" kinda thing. pass realm = GUID_NULL for "default" account, or your own unique name if you need to login with a separate ID from the rest of Winamp
  67. int SetCredentials(GUID realm, const char *session_key, const char *token, const wchar_t *username, __time64_t expire);
  68. int GetCredentials(GUID realm, char *session_key, size_t session_key_len, char *token, size_t token_len, wchar_t *username, size_t username_len, __time64_t *expire);
  69. const char *GetDevID();
  70. int ClientToWeb(GUID realm, const wchar_t *destination_url, wchar_t *url, size_t urlcch);
  71. HWND CreateLoginWindow(GUID realm, HWND owner, UINT style);
  72. INT_PTR LoginBox(GUID realm, HWND owner, UINT style);
  73. int GetUserName(GUID realm, wchar_t *username, size_t username_len);
  74. enum
  75. {
  76. API_AUTH_LOGIN = 0,
  77. API_AUTH_SETCREDENTIALS = 1,
  78. API_AUTH_GETCREDENTIALS = 2,
  79. API_AUTH_GETDEVID = 3,
  80. API_AUTH_LOGIN_SECURID = 4,
  81. API_AUTH_CLIENT_TO_WEB = 5,
  82. API_AUTH_CREATELOGINWINDOW = 6,
  83. API_AUTH_LOGINBOX = 7,
  84. API_AUTH_GETUSERNAME=8,
  85. };
  86. };
  87. inline int api_auth::Login(const wchar_t *username, const wchar_t *password, AuthResults *results, ifc_authcallback *callback)
  88. {
  89. return _call(API_AUTH_LOGIN, (int)AUTH_NOHTTP, username, password, results, callback);
  90. }
  91. inline int api_auth::LoginSecurID(const wchar_t *username, const wchar_t *password, const char *context, const wchar_t *securid, AuthResults *results, ifc_authcallback *callback)
  92. {
  93. return _call(API_AUTH_LOGIN_SECURID, (int)AUTH_NOHTTP, username, password, context, securid, results, callback);
  94. }
  95. inline int api_auth::SetCredentials(GUID realm, const char *session_key, const char *token, const wchar_t *username, __time64_t expire)
  96. {
  97. return _call(API_AUTH_SETCREDENTIALS, (int)AUTH_NOT_AUTHORIZED, realm, session_key, token, username, expire);
  98. }
  99. inline int api_auth::GetCredentials(GUID realm, char *session_key, size_t session_key_len, char *token, size_t token_len, wchar_t *username, size_t username_len, __time64_t *expire)
  100. {
  101. return _call(API_AUTH_GETCREDENTIALS, (int)AUTH_NOT_AUTHORIZED, realm, session_key, session_key_len, token, token_len, username, username_len, expire);
  102. }
  103. inline const char *api_auth::GetDevID()
  104. {
  105. return _call(API_AUTH_GETDEVID, (const char *)0);
  106. }
  107. inline int api_auth::ClientToWeb(GUID realm, const wchar_t *destination_url, wchar_t *url, size_t urlcch)
  108. {
  109. return _call(API_AUTH_CLIENT_TO_WEB, (int)1, realm, destination_url, url, urlcch);
  110. }
  111. inline HWND api_auth::CreateLoginWindow(GUID realm, HWND owner, UINT style)
  112. {
  113. return _call(API_AUTH_CREATELOGINWINDOW, (HWND)NULL, realm, owner, style);
  114. }
  115. inline INT_PTR api_auth::LoginBox(GUID realm, HWND owner, UINT style)
  116. {
  117. return _call(API_AUTH_LOGINBOX, (INT_PTR)-1, realm, owner, style);
  118. }
  119. inline int api_auth::GetUserName(GUID realm, wchar_t *username, size_t username_len)
  120. {
  121. return _call(API_AUTH_GETUSERNAME, (int)AUTH_UNEXPECTED, realm, username, username_len);
  122. }