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
- [ ] Performance optimization
- [ ] Add ability to track the visitors (Referrer, maybe also live)
- [ ] Create Makefile for building everything
- [ ] Test docker-compose installation
- [ ] 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
// un- and marshalling
type URLUtil struct {
URL string
URL string `binding:"required"`
}
type oAuthUser struct {
@ -97,7 +97,6 @@ func (h *Handler) randToken() string {
}
func (h *Handler) handleGoogleAuth(c *gin.Context) {
// Handle the exchange code to initiate a transport.
session := sessions.Default(c)
retrievedState := session.Get("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))
}
func (h *Handler) handleGoogleCallback(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{"Hello": "from private", "user": ctx.MustGet("user").(oAuthUser)})
func (h *Handler) handleGoogleCallback(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"Hello": "from private", "user": c.MustGet("user").(oAuthUser)})
}
// handleCreate handles requests to create an entry
func (h *Handler) handleCreate(c *gin.Context) {
var data struct {
URL string
}
var data URLUtil
err := c.ShouldBind(&data)
if err != nil {
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 = () => {
this.setState({ open: false })
this.setState({ open: true })
}
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() {
@ -49,10 +53,10 @@ class ContainerExampleContainer extends Component {
return (
<Modal size="tiny" open={open} onClose={this.onOAuthClose}>
<Modal.Header>
OAuth2 Authentication
Authentication
</Modal.Header>
<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">
<Button className="ui google plus button" onClick={this.onAuthClick}>
<i className="google icon"></i>

Loading…
Cancel
Save