corrections typo parametre du flow oauth2
This commit is contained in:
@@ -6,11 +6,11 @@ type Oauth struct {
|
|||||||
ID int64 `db:"id"`
|
ID int64 `db:"id"`
|
||||||
AccessToken string `db:"access_token"`
|
AccessToken string `db:"access_token"`
|
||||||
TokenType string `db:"token_type"`
|
TokenType string `db:"token_type"`
|
||||||
ExpireIN int `db:"expire_in"`
|
ExpiresIN float64 `db:"expires_in"`
|
||||||
RefreshToken string `db:"refresh_token"`
|
RefreshToken string `db:"refresh_token"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o Oauth) String() string {
|
func (o Oauth) String() string {
|
||||||
return fmt.Sprintf("id=%v, accessToken=%v, tokenType=%v, expireIN=%v, refreshToken=%v",
|
return fmt.Sprintf("id=%v, accessToken=%v, tokenType=%v, expiresIN=%v, refreshToken=%v",
|
||||||
o.ID, o.AccessToken, o.TokenType, o.ExpireIN, o.RefreshToken)
|
o.ID, o.AccessToken, o.TokenType, o.ExpiresIN, o.RefreshToken)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ func (s *server) handleLocal() http.HandlerFunc {
|
|||||||
ID: 0,
|
ID: 0,
|
||||||
AccessToken: at,
|
AccessToken: at,
|
||||||
TokenType: "bearer",
|
TokenType: "bearer",
|
||||||
ExpireIN: -1,
|
ExpiresIN: -1,
|
||||||
RefreshToken: "refresh",
|
RefreshToken: "refresh",
|
||||||
}
|
}
|
||||||
err = s.store.CreateOauth(o)
|
err = s.store.CreateOauth(o)
|
||||||
@@ -183,12 +183,13 @@ func (s *server) handleRedirect() http.HandlerFunc {
|
|||||||
fmt.Printf("erreur à la recupération des param (err=%v)", err)
|
fmt.Printf("erreur à la recupération des param (err=%v)", err)
|
||||||
}
|
}
|
||||||
jsonStr := constJSONToken(c, st, p)
|
jsonStr := constJSONToken(c, st, p)
|
||||||
log.Printf("jsonStr %v", jsonStr)
|
//log.Printf("jsonStr %v", jsonStr)
|
||||||
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{}
|
||||||
log.Printf("data %v", data)
|
log.Printf("data %v", data)
|
||||||
data.Set("client_id", jsonStr.ClientID)
|
data.Set("client_id", jsonStr.ClientID)
|
||||||
data.Set("client_secret", jsonStr.ClientSecret)
|
data.Set("client_secret", jsonStr.ClientSecret)
|
||||||
|
//"YNVZF88dD4vny59k")
|
||||||
data.Set("grant_type", jsonStr.GrantType)
|
data.Set("grant_type", jsonStr.GrantType)
|
||||||
data.Set("redirect_uri", jsonStr.RedirectURI)
|
data.Set("redirect_uri", jsonStr.RedirectURI)
|
||||||
data.Set("code", jsonStr.Code)
|
data.Set("code", jsonStr.Code)
|
||||||
@@ -198,6 +199,7 @@ func (s *server) handleRedirect() http.HandlerFunc {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("erreur sur le post (err=%v)", err)
|
log.Printf("erreur sur le post (err=%v)", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||||
req.Header.Add("Content-Length", strconv.Itoa(len(data.Encode())))
|
req.Header.Add("Content-Length", strconv.Itoa(len(data.Encode())))
|
||||||
req.Header.Add("Accept", "application/json")
|
req.Header.Add("Accept", "application/json")
|
||||||
@@ -224,13 +226,12 @@ func (s *server) handleRedirect() http.HandlerFunc {
|
|||||||
s.response(rw, r, nil, http.StatusBadGateway)
|
s.response(rw, r, nil, http.StatusBadGateway)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert en base de données
|
// Insert en base de données
|
||||||
o := &model.Oauth{
|
o := &model.Oauth{
|
||||||
ID: 0,
|
ID: 0,
|
||||||
AccessToken: t["access_token"].(string),
|
AccessToken: t["access_token"].(string),
|
||||||
TokenType: t["type_token"].(string),
|
TokenType: t["token_type"].(string),
|
||||||
ExpireIN: t["expire_in"].(int),
|
ExpiresIN: t["expires_in"].(float64),
|
||||||
RefreshToken: t["refresh_token"].(string),
|
RefreshToken: t["refresh_token"].(string),
|
||||||
}
|
}
|
||||||
err = s.store.CreateOauth(o)
|
err = s.store.CreateOauth(o)
|
||||||
@@ -305,7 +306,7 @@ func constJSONToken(code, state string, param *model.Param) 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%3Fstate=" + state,
|
RedirectURI: "http://localhost:8080/oauth/redirect?state=" + state,
|
||||||
Code: code,
|
Code: code,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ CREATE TABLE IF NOT EXISTS oauth
|
|||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
access_token TEXT,
|
access_token TEXT,
|
||||||
token_type TEXT,
|
token_type TEXT,
|
||||||
expire_in INTEGER,
|
expires_in INTEGER,
|
||||||
refresh_token TEXT
|
refresh_token TEXT
|
||||||
)
|
)
|
||||||
`
|
`
|
||||||
@@ -77,8 +77,8 @@ func (store *DbStore) GetOauth(id int64) (*model.Oauth, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (store *DbStore) CreateOauth(o *model.Oauth) error {
|
func (store *DbStore) CreateOauth(o *model.Oauth) error {
|
||||||
res, err := store.db.Exec("INSERT INTO oauth (access_token, token_type, expire_in, refresh_token) VALUES (?, ?, ?, ?)",
|
res, err := store.db.Exec("INSERT INTO oauth (access_token, token_type, expires_in, refresh_token) VALUES (?, ?, ?, ?)",
|
||||||
o.AccessToken, o.TokenType, o.ExpireIN, o.RefreshToken)
|
o.AccessToken, o.TokenType, o.ExpiresIN, o.RefreshToken)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user