Improved authentication
This commit is contained in:
parent
f981be2b7d
commit
ad9870b1c1
@ -8,6 +8,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/aerogo/aero"
|
"github.com/aerogo/aero"
|
||||||
|
"github.com/aerogo/log"
|
||||||
"github.com/animenotifier/notify.moe/arn"
|
"github.com/animenotifier/notify.moe/arn"
|
||||||
"github.com/animenotifier/notify.moe/assets"
|
"github.com/animenotifier/notify.moe/assets"
|
||||||
"github.com/animenotifier/notify.moe/utils"
|
"github.com/animenotifier/notify.moe/utils"
|
||||||
@ -25,8 +26,8 @@ type FacebookUser struct {
|
|||||||
Gender string `json:"gender"`
|
Gender string `json:"gender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// InstallFacebookAuth enables Facebook login for the app.
|
// Facebook enables Facebook login for the app.
|
||||||
func InstallFacebookAuth(app *aero.Application) {
|
func Facebook(app *aero.Application, authLog *log.Log) {
|
||||||
// OAuth2 configuration defines the API keys,
|
// OAuth2 configuration defines the API keys,
|
||||||
// scopes of required data and the redirect URL
|
// scopes of required data and the redirect URL
|
||||||
// that Facebook should send the user to after
|
// that Facebook should send the user to after
|
@ -8,6 +8,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/aerogo/aero"
|
"github.com/aerogo/aero"
|
||||||
|
"github.com/aerogo/log"
|
||||||
"github.com/animenotifier/notify.moe/arn"
|
"github.com/animenotifier/notify.moe/arn"
|
||||||
"github.com/animenotifier/notify.moe/assets"
|
"github.com/animenotifier/notify.moe/assets"
|
||||||
"github.com/animenotifier/notify.moe/utils"
|
"github.com/animenotifier/notify.moe/utils"
|
||||||
@ -30,8 +31,8 @@ type GoogleUser struct {
|
|||||||
// EmailVerified bool `json:"email_verified"`
|
// EmailVerified bool `json:"email_verified"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// InstallGoogleAuth enables Google login for the app.
|
// Google enables Google login for the app.
|
||||||
func InstallGoogleAuth(app *aero.Application) {
|
func Google(app *aero.Application, authLog *log.Log) {
|
||||||
// OAuth2 configuration defines the API keys,
|
// OAuth2 configuration defines the API keys,
|
||||||
// scopes of required data and the redirect URL
|
// scopes of required data and the redirect URL
|
||||||
// that Google should send the user to after
|
// that Google should send the user to after
|
25
auth/Install.go
Normal file
25
auth/Install.go
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package auth
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/aerogo/aero"
|
||||||
|
"github.com/aerogo/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
const newUserStartRoute = "/welcome"
|
||||||
|
|
||||||
|
// Install installs all authentication routes in the application.
|
||||||
|
func Install(app *aero.Application) {
|
||||||
|
authLog := log.New()
|
||||||
|
authLog.AddWriter(os.Stdout)
|
||||||
|
authLog.AddWriter(log.File("logs/auth.log"))
|
||||||
|
|
||||||
|
// Login
|
||||||
|
Google(app, authLog)
|
||||||
|
Facebook(app, authLog)
|
||||||
|
Twitter(app, authLog)
|
||||||
|
|
||||||
|
// Logout
|
||||||
|
Logout(app, authLog)
|
||||||
|
}
|
@ -4,23 +4,13 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/aerogo/aero"
|
"github.com/aerogo/aero"
|
||||||
|
"github.com/aerogo/log"
|
||||||
"github.com/animenotifier/notify.moe/utils"
|
"github.com/animenotifier/notify.moe/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const newUserStartRoute = "/welcome"
|
// Logout is called when the user clicks the logout button.
|
||||||
|
// It deletes the "userId" from the session.
|
||||||
// Install installs the authentication routes in the application.
|
func Logout(app *aero.Application, authLog *log.Log) {
|
||||||
func Install(app *aero.Application) {
|
|
||||||
// Google
|
|
||||||
InstallGoogleAuth(app)
|
|
||||||
|
|
||||||
// Facebook
|
|
||||||
InstallFacebookAuth(app)
|
|
||||||
|
|
||||||
// Twitter
|
|
||||||
InstallTwitterAuth(app)
|
|
||||||
|
|
||||||
// Logout
|
|
||||||
app.Get("/logout", func(ctx aero.Context) error {
|
app.Get("/logout", func(ctx aero.Context) error {
|
||||||
if ctx.HasSession() {
|
if ctx.HasSession() {
|
||||||
user := utils.GetUser(ctx)
|
user := utils.GetUser(ctx)
|
@ -9,6 +9,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/aerogo/aero"
|
"github.com/aerogo/aero"
|
||||||
|
"github.com/aerogo/log"
|
||||||
"github.com/animenotifier/notify.moe/arn"
|
"github.com/animenotifier/notify.moe/arn"
|
||||||
"github.com/animenotifier/notify.moe/assets"
|
"github.com/animenotifier/notify.moe/assets"
|
||||||
"github.com/animenotifier/notify.moe/utils"
|
"github.com/animenotifier/notify.moe/utils"
|
||||||
@ -25,8 +26,8 @@ type TwitterUser struct {
|
|||||||
ScreenName string `json:"screen_name"`
|
ScreenName string `json:"screen_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// InstallTwitterAuth enables Twitter login for the app.
|
// Twitter enables Twitter login for the app.
|
||||||
func InstallTwitterAuth(app *aero.Application) {
|
func Twitter(app *aero.Application, authLog *log.Log) {
|
||||||
// oauth1 configuration defines the API keys,
|
// oauth1 configuration defines the API keys,
|
||||||
// the url for the request token, the access token and the authorisation.
|
// the url for the request token, the access token and the authorisation.
|
||||||
config := &oauth.Client{
|
config := &oauth.Client{
|
14
auth/log.go
14
auth/log.go
@ -1,14 +0,0 @@
|
|||||||
package auth
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/aerogo/log"
|
|
||||||
)
|
|
||||||
|
|
||||||
var authLog = log.New()
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
authLog.AddWriter(os.Stdout)
|
|
||||||
authLog.AddWriter(log.File("logs/auth.log"))
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user