Commit 66ca94a6 authored by ale's avatar ale
Browse files

Fix the otpauth URL when enabling OTP

And some minor style improvements to the account_otp_enable_ok page.
parent e3f5df63
Pipeline #423 passed with stages
in 1 minute and 20 seconds
......@@ -5,21 +5,30 @@
<p>
Two-factor authentication using software OTP tokens has been set
up successfully. You must now set up your client application.
up successfully. You must now set up your client application:
</p>
<p>
Click on a URL:
<blockquote>
<a href="{{.KeyURL}}">{{.KeyURL}}</a>
</blockquote>
</p>
<ul>
<li>
If you're on mobile, you can click on this link:
<blockquote>
<a href="{{.KeyURL}}">{{.KeyURL}}</a>
</blockquote>
</li>
<p>
Scan a QR code:
<img src="data:image/png;base64,{{.QRCode}}">
</p>
<li>
Or you can scan this QR code:
<img src="data:image/png;base64,{{.QRCode}}">
</li>
<li>
Otherwise, enter the secret token manually in your client
application:
<pre>{{.Secret}}</pre>
</li>
</ul>
<p>
<a class="btn btn-default" href="/account/overview">
Done
......
......@@ -47,15 +47,10 @@ func keyToPNG(key *otp.Key) string {
}
func keyToURL(key *otp.Key, username string) string {
u := url.URL{
Scheme: "otpauth",
Host: "totp",
Path: fmt.Sprintf("%s:%s", idp.OTPIssuer, username),
}
q := u.Query()
q.Set("secret", key.Secret())
q.Set("issuer", idp.OTPIssuer)
return u.String()
v := make(url.Values)
v.Set("secret", key.Secret())
v.Set("issuer", idp.OTPIssuer)
return fmt.Sprintf("otpauth://totp/%s:%s?%s", idp.OTPIssuer, username, v.Encode())
}
func (s *Service) handleOTPEnablePart2(w http.ResponseWriter, r *http.Request, txn idp.Txn, user *idp.User, templateName string) error {
......@@ -79,6 +74,7 @@ func (s *Service) handleOTPEnablePart2(w http.ResponseWriter, r *http.Request, t
tplCtx["QRCode"] = keyToPNG(key)
tplCtx["KeyURL"] = keyToURL(key, user.Name)
tplCtx["Secret"] = key.Secret()
s.RenderTemplate(w, r, "account_otp_enable_ok.html", tplCtx)
return nil
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment