1234567891011121314151617181920212223242526272829303132333435 |
- package service
- /*func TestGetAccessToken(t *testing.T) {
- // Create the token
- token := jwt.New(jwt.SigningMethodRS256)
- // Set some claims
- token.Claims["iss"] = "webfront@xniao.com"
- token.Claims["scope"] = "api.xiaoniaokuaiyan.com"
- token.Claims["aud"] = "api.xiaoniaokuaiyan.com/auth/token"
- token.Claims["iat"] = time.Now().Unix()
- token.Claims["exp"] = time.Now().Add(time.Hour * 72).Unix()
- // Sign and get the complete encoded token
- // as a string
- mySigningKey, _ := ioutil.ReadFile("./privkey.pem")
- tokenString, err := token.SignedString(mySigningKey)
- if err != nil {
- log.Fatal(err)
- }
- //fmt.Println(tokenString)
- var postParam = &url.Values{}
- postParam.Add("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer")
- postParam.Add("assertion", tokenString)
- //res,
- //err
- //:=
- //http.Post("http://localhost:8080/oauth2/token",
- //"application/x-www-form-urlencoded",
- //strings.NewReader("grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion="+tokenString))
- res, err := http.PostForm("http://localhost:8000/auth/token", *postParam)
- if err != nil {
- log.Fatal(err)
- }
- rbytes, _ := ioutil.ReadAll(res.Body)
- fmt.Println(string(rbytes))
- }*/
|