Esempio n. 1
0
// SignInComplete finishes authentication process.
func SignInComplete(c *gin.Context) {
	service := c.Param("service")
	if err := oauth2.HandleService(service); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{})
		return
	}

	var b signInCompleteBinding
	if err := c.Bind(&b); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{})
		return
	}

	if err := oauth2.ValidateAuthorizeRequest(service, b.State); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{})
		return
	}

	user, err := oauth2.FinishAuthorizeRequest(service, b.Code)
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{})
		return
	}

	token, _ := models.CreateUserToken(user.ID, "Auth "+time.Now().String())

	c.JSON(http.StatusOK, gin.H{
		"user": gin.H{
			"id":    user.ID,
			"token": token.Value,
		},
	})
}
Esempio n. 2
0
// SignIn starts authentication process.
func SignIn(c *gin.Context) {
	service := c.Param("service")
	if err := oauth2.HandleService(service); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{})
		return
	}

	redirectURL := oauth2.HandleAuthorizeRequest(service)

	c.JSON(http.StatusOK, gin.H{
		"redirectURL": redirectURL,
	})
}
Esempio n. 3
0
File: repos.go Progetto: Gr1N/pacman
// ReposList returns list of user repos for specified service.
func ReposList(c *gin.Context) {
	service := c.Param("service")
	if err := oauth2.HandleService(service); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{})
		return
	}

	user := middleware.UserFromContext(c)
	repos, _ := models.GetUserReposByService(user.ID, service)

	c.JSON(http.StatusOK, gin.H{
		"list":  repos,
		"total": len(repos),
	})
}