Start adding openid auth handler

This commit is contained in:
kolaente 2020-10-25 15:50:29 +01:00
parent ac6d0a6472
commit 776dc3598c
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 86 additions and 6 deletions

View File

@ -0,0 +1,73 @@
// Vikunja is a to-do list application to facilitate your life.
// Copyright 2018-2020 Vikunja and contributors. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package openid
import (
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/models"
"github.com/labstack/echo/v4"
"net/http"
)
type Callback struct {
Code string `query:"code" json:"code"`
Scope string `query:"scop" json:"scope"`
State string `query:"state" json:"state"`
}
type Provider struct {
Name string `json:"name"`
AuthURL string `json:"auth_url"`
ClientID string `json:"client_id"`
}
func GetAllProviders() (providers []*Provider) {
rawProvider := config.AuthOpenIDProviders.Get().([]interface{})
for _, p := range rawProvider {
pi := p.(map[interface{}]interface{})
providers = append(providers, &Provider{
Name: pi["name"].(string),
AuthURL: pi["authurl"].(string),
ClientID: pi["clientid"].(string),
})
}
return
}
func HandleCallback(c echo.Context) error {
cb := &Callback{}
if err := c.Bind(cb); err != nil {
return c.JSON(http.StatusBadRequest, models.Message{Message: "Bad data"})
}
// Check if the provider exists
//providerKey := c.Param("provider")
// Parse the access & ID token
// Get the userinfo
// Check if we have seen this user before
// Log them in
return nil
}

View File

@ -47,6 +47,7 @@
package routes
import (
"code.vikunja.io/api/pkg/modules/auth/openid"
"strings"
"time"
@ -220,12 +221,18 @@ func registerAPIRoutes(a *echo.Group) {
// Prometheus endpoint
setupMetrics(n)
// User stuff
n.POST("/login", apiv1.Login)
n.POST("/register", apiv1.RegisterUser)
n.POST("/user/password/token", apiv1.UserRequestResetPasswordToken)
n.POST("/user/password/reset", apiv1.UserResetPassword)
n.POST("/user/confirm", apiv1.UserConfirmEmail)
if config.AuthLocalEnabled.GetBool() {
// User stuff
n.POST("/login", apiv1.Login)
n.POST("/register", apiv1.RegisterUser)
n.POST("/user/password/token", apiv1.UserRequestResetPasswordToken)
n.POST("/user/password/reset", apiv1.UserResetPassword)
n.POST("/user/confirm", apiv1.UserConfirmEmail)
}
if config.AuthOpenIDEnabled.GetBool() {
n.POST("/auth/openid/:provider/callback", openid.HandleCallback)
}
// Info endpoint
n.GET("/info", apiv1.Info)