This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package pages | |
/* | |
IndexPage renders the html content for the index page. | |
*/ | |
const IndexPage = ` | |
<html> | |
<head> | |
<title>OAuth-2 Test</title> | |
</head> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package services | |
import ( | |
"io/ioutil" | |
"net/http" | |
"net/url" | |
"github.com/BNPrashanth/poc-go-oauth2/internal/logger" | |
"github.com/spf13/viper" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package configs | |
import ( | |
"fmt" | |
"github.com/spf13/viper" | |
) | |
/* | |
InitializeViper Function initializes viper to read config.yml file and environment variables in the application. |
NewerOlder