Skip to content

Instantly share code, notes, and snippets.

View BNPrashanth's full-sized avatar

Prashanth BNPrashanth

  • Colombo, Sri Lanka
View GitHub Profile
package services
import (
"net/http"
"net/url"
"strings"
"github.com/BNPrashanth/poc-go-oauth2/internal/helpers/pages"
"github.com/BNPrashanth/poc-go-oauth2/internal/logger"
"golang.org/x/oauth2"
/*
HandleMain Function renders the index page when the application index route is called
*/
func HandleMain(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusOK)
w.Write([]byte(pages.IndexPage))
}
package pages
/*
IndexPage renders the html content for the index page.
*/
const IndexPage = `
<html>
<head>
<title>OAuth-2 Test</title>
</head>
package services
import (
"io/ioutil"
"net/http"
"net/url"
"github.com/BNPrashanth/poc-go-oauth2/internal/logger"
"github.com/spf13/viper"
/*
HandleLogin Function
*/
func HandleLogin(w http.ResponseWriter, r *http.Request, oauthConf *oauth2.Config, oauthStateString string) {
URL, err := url.Parse(oauthConf.Endpoint.AuthURL)
if err != nil {
logger.Log.Error("Parse: " + err.Error())
}
logger.Log.Info(URL.String())
parameters := url.Values{}
var (
oauthConfGl = &oauth2.Config{
ClientID: "",
ClientSecret: "",
RedirectURL: "http://localhost:9090/callback-gl",
Scopes: []string{"https://www.googleapis.com/auth/userinfo.email"},
Endpoint: google.Endpoint,
}
oauthStateStringGl = ""
)
var (
oauthConfGl = &oauth2.Config{
ClientID: "",
ClientSecret: "",
RedirectURL: "http://localhost:9090/callback-gl",
Scopes: []string{"https://www.googleapis.com/auth/userinfo.email"},
Endpoint: google.Endpoint,
}
oauthStateStringGl = ""
)
package main
import (
"log"
"net/http"
"github.com/gs-open-provider/poc-go-oauth2/internal/configs"
"github.com/gs-open-provider/poc-go-oauth2/internal/logger"
"github.com/gs-open-provider/poc-go-oauth2/internal/services"
package logger
import (
"github.com/spf13/viper"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
var (
// Log variable is a globally accessible variable which will be initialized when the InitializeZapCustomLogger function is executed successfully.
package configs
import (
"fmt"
"github.com/spf13/viper"
)
/*
InitializeViper Function initializes viper to read config.yml file and environment variables in the application.