ajout du champ state dans redirecturi pour récupérer les params
This commit is contained in:
@@ -46,12 +46,12 @@ type Claims struct {
|
|||||||
func (s *server) handleIndex() http.HandlerFunc {
|
func (s *server) handleIndex() http.HandlerFunc {
|
||||||
return func(rw http.ResponseWriter, r *http.Request) {
|
return func(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
err := s.store.DeleteOauth()
|
err := s.store.DeleteOauth(1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("erreur à la récupération des paramètres %v", err)
|
fmt.Printf("erreur à la récupération des paramètres %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.store.DeleteParam()
|
err = s.store.DeleteParam("state")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("erreur à la récupération des paramètres %v", err)
|
fmt.Printf("erreur à la récupération des paramètres %v", err)
|
||||||
}
|
}
|
||||||
@@ -161,7 +161,7 @@ func (s *server) handleOAuth20() http.HandlerFunc {
|
|||||||
rhttp := "https://" + d + "/entreprise-partenaire/authorize?client_id=" + ci +
|
rhttp := "https://" + d + "/entreprise-partenaire/authorize?client_id=" + ci +
|
||||||
"&scope=" + sc +
|
"&scope=" + sc +
|
||||||
"¤t_company=" + cc +
|
"¤t_company=" + cc +
|
||||||
"&redirect_uri=http://localhost:8080/oauth/redirect" +
|
"&redirect_uri=http://localhost:8080/oauth/redirect%3Fstate=ererer" +
|
||||||
"&abort_uri=http://localhost:8080/index"
|
"&abort_uri=http://localhost:8080/index"
|
||||||
http.Redirect(rw, r, rhttp, http.StatusMovedPermanently)
|
http.Redirect(rw, r, rhttp, http.StatusMovedPermanently)
|
||||||
|
|
||||||
@@ -172,12 +172,15 @@ func (s *server) handleOAuth20() http.HandlerFunc {
|
|||||||
func (s *server) handleRedirect() http.HandlerFunc {
|
func (s *server) handleRedirect() http.HandlerFunc {
|
||||||
return func(rw http.ResponseWriter, r *http.Request) {
|
return func(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
codes, _ := r.URL.Query()["code"]
|
c := r.URL.Query().Get("code")
|
||||||
p, err := s.store.GetParam()
|
st := r.URL.Query().Get("state")
|
||||||
|
|
||||||
|
// ici jouter la récupération du param
|
||||||
|
p, err := s.store.GetParam(st)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("erreur à la recupération des param (err=%v)", err)
|
fmt.Printf("erreur à la recupération des param (err=%v)", err)
|
||||||
}
|
}
|
||||||
jsonStr := constJSONToken(codes[0], p)
|
jsonStr := constJSONToken(c, st, p)
|
||||||
|
|
||||||
apiURL := "https://api." + p.Domaine + "/auth/v1/oauth2.0/accessToken"
|
apiURL := "https://api." + p.Domaine + "/auth/v1/oauth2.0/accessToken"
|
||||||
data := url.Values{}
|
data := url.Values{}
|
||||||
@@ -228,8 +231,9 @@ func (s *server) handleRedirect() http.HandlerFunc {
|
|||||||
fmt.Printf("erreur suivante %v", err)
|
fmt.Printf("erreur suivante %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
monID := strconv.Itoa(int(o.ID))
|
||||||
// Puis redisrect vers page resultat
|
// Puis redisrect vers page resultat
|
||||||
rj := "http://localhost:8080/jwt"
|
rj := "http://localhost:8080/jwt?model=" + monID
|
||||||
http.Redirect(rw, r, rj, http.StatusMovedPermanently)
|
http.Redirect(rw, r, rj, http.StatusMovedPermanently)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -244,7 +248,7 @@ func (s *server) handleJSONWebToken() http.HandlerFunc {
|
|||||||
fmt.Printf("erreur suivante %v", err)
|
fmt.Printf("erreur suivante %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
oauth, _ := s.store.GetOauth()
|
oauth, _ := s.store.GetOauth(1)
|
||||||
tokenVal := oauth.AccessToken
|
tokenVal := oauth.AccessToken
|
||||||
|
|
||||||
fmt.Println("============")
|
fmt.Println("============")
|
||||||
@@ -281,12 +285,12 @@ func (s *server) handleJSONWebToken() http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func constJSONToken(code string, param *model.Param) JSONToken {
|
func constJSONToken(code, state string, param *model.Param) JSONToken {
|
||||||
return JSONToken{
|
return JSONToken{
|
||||||
ClientID: param.ClientID,
|
ClientID: param.ClientID,
|
||||||
ClientSecret: param.ClientSecret,
|
ClientSecret: param.ClientSecret,
|
||||||
GrantType: param.GrantType,
|
GrantType: param.GrantType,
|
||||||
RedirectURI: "http://localhost:8080/oauth/redirect",
|
RedirectURI: "http://localhost:8080/oauth/redirect?state=" + state,
|
||||||
Code: code,
|
Code: code,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ type Store interface {
|
|||||||
Open() error
|
Open() error
|
||||||
Close() error
|
Close() error
|
||||||
|
|
||||||
GetOauth() (*model.Oauth, error)
|
GetOauth(id int64) (*model.Oauth, error)
|
||||||
CreateOauth(m *model.Oauth) error
|
CreateOauth(m *model.Oauth) error
|
||||||
DeleteOauth() error
|
DeleteOauth(id int64) error
|
||||||
|
|
||||||
GetParam() (*model.Param, error)
|
GetParam(state string) (*model.Param, error)
|
||||||
CreateParam(m *model.Param) error
|
CreateParam(m *model.Param) error
|
||||||
DeleteParam() error
|
DeleteParam(state string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type DbStore struct {
|
type DbStore struct {
|
||||||
@@ -64,9 +64,9 @@ func (store *DbStore) Close() error {
|
|||||||
return store.db.Close()
|
return store.db.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store *DbStore) GetOauth() (*model.Oauth, error) {
|
func (store *DbStore) GetOauth(id int64) (*model.Oauth, error) {
|
||||||
var oauth = &model.Oauth{}
|
var oauth = &model.Oauth{}
|
||||||
err := store.db.Get(oauth, "SELECT * FROM oauth")
|
err := store.db.Get(oauth, "SELECT * FROM oauth where id=$1", id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return oauth, err
|
return oauth, err
|
||||||
}
|
}
|
||||||
@@ -86,8 +86,8 @@ func (store *DbStore) CreateOauth(o *model.Oauth) error {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store *DbStore) DeleteOauth() error {
|
func (store *DbStore) DeleteOauth(id int64) error {
|
||||||
_, err := store.db.Exec("DELETE FROM oauth", nil)
|
_, err := store.db.Exec("DELETE FROM oauth where id=?", id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -95,9 +95,9 @@ func (store *DbStore) DeleteOauth() error {
|
|||||||
return err
|
return err
|
||||||
|
|
||||||
}
|
}
|
||||||
func (store *DbStore) GetParam() (*model.Param, error) {
|
func (store *DbStore) GetParam(state string) (*model.Param, error) {
|
||||||
var param = &model.Param{}
|
var param = &model.Param{}
|
||||||
err := store.db.Get(param, "SELECT * FROM param")
|
err := store.db.Get(param, "SELECT * FROM param where state=$1", state)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return param, err
|
return param, err
|
||||||
}
|
}
|
||||||
@@ -116,8 +116,8 @@ func (store *DbStore) CreateParam(p *model.Param) error {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store *DbStore) DeleteParam() error {
|
func (store *DbStore) DeleteParam(state string) error {
|
||||||
_, err := store.db.Exec("DELETE FROM param", nil)
|
_, err := store.db.Exec("DELETE FROM param where state=?", state)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user