Browse Source

improved oAuth logic

dependabot/npm_and_yarn/web/prismjs-1.21.0
Schmitt, Max 8 years ago
parent
commit
95143657ca
  1. 1
      README.md
  2. 11
      handlers/handlers.go
  3. BIN
      static/public/favicon.ico
  4. 12
      static/src/App/App.js

1
README.md

@ -138,5 +138,6 @@ Next changes sorted by priority
- [ ] Refactore Unit Tests - [ ] Refactore Unit Tests
- [ ] Performance optimization - [ ] Performance optimization
- [ ] Add ability to track the visitors (Referrer, maybe also live) - [ ] Add ability to track the visitors (Referrer, maybe also live)
- [ ] Create Makefile for building everything
- [ ] Test docker-compose installation - [ ] Test docker-compose installation
- [ ] Provide image on the docker hub - [ ] Provide image on the docker hub

11
handlers/handlers.go

@ -29,7 +29,7 @@ type Handler struct {
// URLUtil is used to help in- and outgoing requests for json // URLUtil is used to help in- and outgoing requests for json
// un- and marshalling // un- and marshalling
type URLUtil struct { type URLUtil struct {
URL string URL string `binding:"required"`
} }
type oAuthUser struct { type oAuthUser struct {
@ -97,7 +97,6 @@ func (h *Handler) randToken() string {
} }
func (h *Handler) handleGoogleAuth(c *gin.Context) { func (h *Handler) handleGoogleAuth(c *gin.Context) {
// Handle the exchange code to initiate a transport.
session := sessions.Default(c) session := sessions.Default(c)
retrievedState := session.Get("state") retrievedState := session.Get("state")
if retrievedState != c.Query("state") { if retrievedState != c.Query("state") {
@ -141,15 +140,13 @@ func (h *Handler) handleGoogleLogin(c *gin.Context) {
c.Redirect(http.StatusTemporaryRedirect, h.oAuthConf.AuthCodeURL(state)) c.Redirect(http.StatusTemporaryRedirect, h.oAuthConf.AuthCodeURL(state))
} }
func (h *Handler) handleGoogleCallback(ctx *gin.Context) { func (h *Handler) handleGoogleCallback(c *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{"Hello": "from private", "user": ctx.MustGet("user").(oAuthUser)}) c.JSON(http.StatusOK, gin.H{"Hello": "from private", "user": c.MustGet("user").(oAuthUser)})
} }
// handleCreate handles requests to create an entry // handleCreate handles requests to create an entry
func (h *Handler) handleCreate(c *gin.Context) { func (h *Handler) handleCreate(c *gin.Context) {
var data struct { var data URLUtil
URL string
}
err := c.ShouldBind(&data) err := c.ShouldBind(&data)
if err != nil { if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})

BIN
static/public/favicon.ico

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 15 KiB

12
static/src/App/App.js

@ -22,12 +22,16 @@ class ContainerExampleContainer extends Component {
} }
onOAuthClose = () => { onOAuthClose = () => {
this.setState({ open: false }) this.setState({ open: true })
} }
onAuthClick = () => { onAuthClick = () => {
console.log("onAuthClick") console.log("onAuthClick")
window.open("/api/v1/login", "", "width=600,height=400") var wwidth = 400,
wHeight = 500;
var wLeft = (window.screen.width / 2) - (wwidth / 2);
var wTop = (window.screen.height / 2) - (wHeight / 2);
window.open("/api/v1/login", "", `width=${wwidth}, height=${wHeight}, top=${wTop}, left=${wLeft}`)
} }
render() { render() {
@ -49,10 +53,10 @@ class ContainerExampleContainer extends Component {
return ( return (
<Modal size="tiny" open={open} onClose={this.onOAuthClose}> <Modal size="tiny" open={open} onClose={this.onOAuthClose}>
<Modal.Header> <Modal.Header>
OAuth2 Authentication Authentication
</Modal.Header> </Modal.Header>
<Modal.Content> <Modal.Content>
<p>Currently you are only able to use Google as authentification service:</p> <p>Currently you are only able to use Google as authentication service:</p>
<div className="ui center aligned segment"> <div className="ui center aligned segment">
<Button className="ui google plus button" onClick={this.onAuthClick}> <Button className="ui google plus button" onClick={this.onAuthClick}>
<i className="google icon"></i> <i className="google icon"></i>

Loading…
Cancel
Save