45 #include <Wt/Auth/Dbo/UserDatabase.h> 46 #include <Wt/Auth/AuthService.h> 47 #include <Wt/Auth/HashFunction.h> 48 #include <Wt/Auth/PasswordService.h> 49 #include <Wt/Auth/PasswordStrengthValidator.h> 50 #include <Wt/Auth/PasswordVerifier.h> 51 #include <Wt/Auth/GoogleService.h> 52 #include <Wt/Auth/FacebookService.h> 53 #include <Wt/Auth/Dbo/AuthInfo.h> 59 session.mapClass<AuthInfo>(
"sysAuthInfo" );
60 session.mapClass<AuthInfo::AuthIdentityType>(
"sysAuthIdentity" );
61 session.mapClass<AuthInfo::AuthTokenType>(
"sysAuthToken" );
72 typedef Wt::Auth::Dbo::UserDatabase<AuthInfo> UserDatabase;
74 Wt::Dbo::Transaction t(session);
75 UserDatabase users( session, &Wtx::Sys::Auth::service() );
77 auto authUser = users.registerNew();
78 authUser.addIdentity( Wt::Auth::Identity::LoginName,
"admin" );
79 authUser.setEmail(
"mark@lorimarksolutions.com" );
80 passwordService().updatePassword( authUser,
"ABC123!!!" );
85 Wt::Auth::AuthService myAuthService;
86 Wt::Auth::PasswordService myPasswordService( myAuthService );
87 std::vector<std::unique_ptr<Wt::Auth::OAuthService>> myOAuthServices;
90 void Wtx::Sys::Auth::configure()
92 myAuthService.setAuthTokensEnabled(
true,
"logincookie" );
93 myAuthService.setEmailVerificationEnabled(
true );
94 myAuthService.setEmailVerificationRequired(
true );
95 myAuthService.setIdentityPolicy( Wt::Auth::IdentityPolicy::EmailAddress );
98 = std::make_unique<Wt::Auth::PasswordVerifier>();
99 verifier->addHashFunction( std::make_unique<Wt::Auth::BCryptHashFunction>(7) );
100 myPasswordService.setVerifier( std::move(verifier) );
101 myPasswordService.setAttemptThrottlingEnabled(
true );
102 myPasswordService.setStrengthValidator( std::make_unique<Wt::Auth::PasswordStrengthValidator>() );
104 if( Wt::Auth::GoogleService::configured() )
105 myOAuthServices.push_back( std::make_unique<Wt::Auth::GoogleService>( myAuthService ) );
107 if( Wt::Auth::FacebookService::configured() )
108 myOAuthServices.push_back( std::make_unique<Wt::Auth::FacebookService>( myAuthService ) );
110 for(
unsigned i = 0; i < myOAuthServices.size(); ++i )
111 myOAuthServices[i]-> generateRedirectEndpoint();
115 const Wt::Auth::AuthService & Wtx::Sys::Auth::service()
117 return myAuthService;
120 const Wt::Auth::PasswordService& Wtx::Sys::Auth::passwordService()
122 return myPasswordService;
125 const std::vector<const Wt::Auth::OAuthService *> Wtx::Sys::Auth::oService()
127 std::vector<const Wt::Auth::OAuthService *> result;
129 for(
auto & auth : myOAuthServices )
130 result.push_back( auth.get() );