eedb/src/eedb/auth/Services.cpp
2018-01-25 10:49:11 +01:00

67 lines
2.0 KiB
C++

#include <eedb/auth/Services.hpp>
#include <Wt/Auth/PasswordService.h>
#include <Wt/Auth/PasswordStrengthValidator.h>
#include <Wt/Auth/PasswordVerifier.h>
#include <Wt/Auth/AuthService.h>
#include <Wt/Auth/AuthWidget.h>
#include <Wt/Auth/Dbo/AuthInfo.h>
#include <Wt/Auth/Dbo/UserDatabase.h>
#include <Wt/Auth/FacebookService.h>
#include <Wt/Auth/GoogleService.h>
#include <Wt/Auth/HashFunction.h>
#include <Wt/Auth/Login.h>
namespace {
class MyOAuth : public std::vector< const Wt::Auth::OAuthService * > {
public:
~MyOAuth() {
for(unsigned i = 0; i < size(); ++i)
delete(*this)[i];
}
};
Wt::Auth::AuthService myAuthService;
Wt::Auth::PasswordService myPasswordService(myAuthService);
MyOAuth myOAuthServices;
}
namespace eedb::auth {
Wt::Auth::AuthService * Services::authService() {
return &myAuthService;
}
Wt::Auth::AbstractPasswordService * Services::passwordService() {
return &myPasswordService;
}
std::vector< const Wt::Auth::OAuthService * > Services::oAuthServices() {
return myOAuthServices;
}
void Services::configureAuth() {
myAuthService.setAuthTokensEnabled(true, "logincookie");
myAuthService.setEmailVerificationEnabled(true);
myAuthService.setEmailVerificationRequired(true);
{
auto verifier = std::unique_ptr<Wt::Auth::PasswordVerifier>();
verifier->addHashFunction(std::make_unique< Wt::Auth::BCryptHashFunction >(7));
myPasswordService.setVerifier(std::move(verifier));
}
myPasswordService.setAttemptThrottlingEnabled(true);
myPasswordService.setStrengthValidator(std::make_unique< Wt::Auth::PasswordStrengthValidator >());
if(Wt::Auth::GoogleService::configured())
myOAuthServices.push_back(new Wt::Auth::GoogleService(myAuthService));
if(Wt::Auth::FacebookService::configured())
myOAuthServices.push_back(new Wt::Auth::FacebookService(myAuthService));
for(unsigned i = 0; i < myOAuthServices.size(); ++i)
myOAuthServices[i]->generateRedirectEndpoint();
}
};