Skip to content

Commit

Permalink
[fix] add missing oauth handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
asciimoo committed Jan 1, 2025
1 parent 90229da commit a04908e
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions webapp/oauth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-FileContributor: Adam Tauber <[email protected]>
//
// SPDX-License-Identifier: AGPLv3+

package webapp

import (
"fmt"
"log"
"net/http"
"net/url"
"strings"

"github.com/asciimoo/omnom/config"

"github.com/gin-gonic/gin"
)

func oauthHandler(c *gin.Context) {
cfg, _ := c.Get("config")
providers := cfg.(*config.Config).OAuth
provider, found := providers[c.Query("provider")]
if !found {
setNotification(c, nError, "Unknown OAuth provider", false)
c.Redirect(http.StatusFound, URLFor("Login"))
return
}

params := url.Values{}
params.Add("client_id", provider.ClientID)
params.Add("scope", strings.Join(provider.Scopes, ","))
params.Add("response_type", "code")
params.Add("redirect_uri", getFullURLPrefix(c)+URLFor("Oauth verification")+"?provider="+c.Query("provider"))

reqURL := fmt.Sprintf("%s?%s", provider.AuthURL, params.Encode())

log.Println("New OAUTH verification:", reqURL, provider)
c.Redirect(http.StatusFound, reqURL)
}

func oauthRedirectHandler(c *gin.Context) {
cfg, _ := c.Get("config")
providers := cfg.(*config.Config).OAuth
provider, found := providers[c.Query("provider")]
if !found {
setNotification(c, nError, "Failed OAuth login", false)
c.Redirect(http.StatusFound, URLFor("Login"))
return
}
params := url.Values{}
reqURL := fmt.Sprintf("%s?%s", provider.TokenURL, params.Encode())
log.Println("New OAUTH verification:", reqURL)
// TODO
}

0 comments on commit a04908e

Please sign in to comment.