mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-19 00:36:38 +00:00
add support for some basic authentication methods
This commit is contained in:
57
proxy/internal/auth/link.go
Normal file
57
proxy/internal/auth/link.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/netbirdio/netbird/shared/management/proto"
|
||||
)
|
||||
|
||||
const linkFormId = "email"
|
||||
|
||||
type Link struct {
|
||||
id, accountId string
|
||||
client authenticator
|
||||
}
|
||||
|
||||
func NewLink(client authenticator, id, accountId string) Link {
|
||||
return Link{
|
||||
id: id,
|
||||
accountId: accountId,
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
|
||||
func (Link) Type() Method {
|
||||
return MethodLink
|
||||
}
|
||||
|
||||
func (l Link) Authenticate(r *http.Request) (string, bool, any) {
|
||||
email := r.FormValue(linkFormId)
|
||||
|
||||
res, err := l.client.Authenticate(r.Context(), &proto.AuthenticateRequest{
|
||||
Id: l.id,
|
||||
AccountId: l.accountId,
|
||||
Request: &proto.AuthenticateRequest_Link{
|
||||
Link: &proto.LinkRequest{
|
||||
Email: email,
|
||||
Redirect: "", // TODO: calculate this.
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
// TODO: log error here
|
||||
return "", false, linkFormId
|
||||
}
|
||||
|
||||
if res.GetSuccess() {
|
||||
// Use the email address as the user identifier.
|
||||
return email, true, nil
|
||||
}
|
||||
|
||||
return "", false, linkFormId
|
||||
}
|
||||
|
||||
func (l Link) Middleware(next http.Handler) http.Handler {
|
||||
// TODO: handle magic link redirects, should be similar to OIDC.
|
||||
return next
|
||||
}
|
||||
Reference in New Issue
Block a user