example_test.go 985 B

12345678910111213141516171819202122232425262728293031
  1. // Copyright 2014 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package jwt_test
  5. import (
  6. "golang.org/x/oauth2"
  7. "golang.org/x/oauth2/jwt"
  8. )
  9. func ExampleJWTConfig() {
  10. conf := &jwt.Config{
  11. Email: "xxx@developer.com",
  12. // The contents of your RSA private key or your PEM file
  13. // that contains a private key.
  14. // If you have a p12 file instead, you
  15. // can use `openssl` to export the private key into a pem file.
  16. //
  17. // $ openssl pkcs12 -in key.p12 -out key.pem -nodes
  18. //
  19. // It only supports PEM containers with no passphrase.
  20. PrivateKey: []byte("-----BEGIN RSA PRIVATE KEY-----..."),
  21. Subject: "user@example.com",
  22. TokenURL: "https://provider.com/o/oauth2/token",
  23. }
  24. // Initiate an http.Client, the following GET request will be
  25. // authorized and authenticated on the behalf of user@example.com.
  26. client := conf.Client(oauth2.NoContext)
  27. client.Get("...")
  28. }