@@ -23,6 +23,9 @@ import (
23
23
"github.com/volatiletech/authboss/lock"
24
24
_ "github.com/volatiletech/authboss/logout"
25
25
aboauth "github.com/volatiletech/authboss/oauth2"
26
+ "github.com/volatiletech/authboss/otp/twofactor"
27
+ "github.com/volatiletech/authboss/otp/twofactor/sms2fa"
28
+ "github.com/volatiletech/authboss/otp/twofactor/totp2fa"
26
29
_ "github.com/volatiletech/authboss/recover"
27
30
_ "github.com/volatiletech/authboss/register"
28
31
"github.com/volatiletech/authboss/remember"
@@ -104,6 +107,10 @@ func setupAuthboss() {
104
107
// to type them again)
105
108
ab .Config .Modules .RegisterPreserveFields = []string {"email" , "name" }
106
109
110
+ // TOTP2FAIssuer is the name of the issuer we use for totp 2fa
111
+ ab .Config .Modules .TOTP2FAIssuer = "ABBlog"
112
+ ab .Config .Modules .TwoFactorRedirectOnUnauthed = true
113
+
107
114
// This instantiates and uses every default implementation
108
115
// in the Config.Core area that exist in the defaults package.
109
116
// Just a convenient helper if you don't want to do anything fancy.
@@ -148,6 +155,22 @@ func setupAuthboss() {
148
155
ClientSecret string `toml:"client_secret"`
149
156
}{}
150
157
158
+ // Set up 2fa
159
+ twofaRecovery := & twofactor.Recovery {Authboss : ab }
160
+ if err := twofaRecovery .Setup (); err != nil {
161
+ panic (err )
162
+ }
163
+
164
+ totp := & totp2fa.TOTP {Authboss : ab }
165
+ if err := totp .Setup (); err != nil {
166
+ panic (err )
167
+ }
168
+
169
+ sms := & sms2fa.SMS {Authboss : ab , Sender : smsLogSender {}}
170
+ if err := sms .Setup (); err != nil {
171
+ panic (err )
172
+ }
173
+
151
174
// Set up Google OAuth2 if we have credentials in the
152
175
// file oauth2.toml for it.
153
176
_ , err := toml .DecodeFile ("oauth2.toml" , & oauthcreds )
@@ -225,7 +248,7 @@ func main() {
225
248
226
249
// Authed routes
227
250
mux .Group (func (mux chi.Router ) {
228
- mux .Use (authboss .Middleware (ab , true , false ), lock .Middleware (ab ), confirm .Middleware (ab ))
251
+ mux .Use (authboss .Middleware (ab , true , false , true ), lock .Middleware (ab ), confirm .Middleware (ab ))
229
252
mux .MethodFunc ("GET" , "/blogs/new" , newblog )
230
253
mux .MethodFunc ("GET" , "/blogs/{id}/edit" , edit )
231
254
mux .MethodFunc ("POST" , "/blogs/{id}/edit" , update )
@@ -503,3 +526,12 @@ func badRequest(w http.ResponseWriter, err error) bool {
503
526
fmt .Fprintln (w , "Bad request:" , err )
504
527
return true
505
528
}
529
+
530
+ type smsLogSender struct {
531
+ }
532
+
533
+ // Send an SMS
534
+ func (s smsLogSender ) Send (number , text string ) error {
535
+ fmt .Println ("sms sent to:" , number , "contents:" , text )
536
+ return nil
537
+ }
0 commit comments