auth_service_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package service
  2. /*func TestGetAccessToken(t *testing.T) {
  3. // Create the token
  4. token := jwt.New(jwt.SigningMethodRS256)
  5. // Set some claims
  6. token.Claims["iss"] = "webfront@xniao.com"
  7. token.Claims["scope"] = "api.xiaoniaokuaiyan.com"
  8. token.Claims["aud"] = "api.xiaoniaokuaiyan.com/auth/token"
  9. token.Claims["iat"] = time.Now().Unix()
  10. token.Claims["exp"] = time.Now().Add(time.Hour * 72).Unix()
  11. // Sign and get the complete encoded token
  12. // as a string
  13. mySigningKey, _ := ioutil.ReadFile("./privkey.pem")
  14. tokenString, err := token.SignedString(mySigningKey)
  15. if err != nil {
  16. log.Fatal(err)
  17. }
  18. //fmt.Println(tokenString)
  19. var postParam = &url.Values{}
  20. postParam.Add("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer")
  21. postParam.Add("assertion", tokenString)
  22. //res,
  23. //err
  24. //:=
  25. //http.Post("http://localhost:8080/oauth2/token",
  26. //"application/x-www-form-urlencoded",
  27. //strings.NewReader("grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion="+tokenString))
  28. res, err := http.PostForm("http://localhost:8000/auth/token", *postParam)
  29. if err != nil {
  30. log.Fatal(err)
  31. }
  32. rbytes, _ := ioutil.ReadAll(res.Body)
  33. fmt.Println(string(rbytes))
  34. }*/