mirror of
https://github.com/golang/oauth2.git
synced 2025-07-21 00:00:09 +08:00
There is no good reason why we suggest NoContext rather than context.Background(). When the oauth2 library first came around, the community was not familiar with the x/net/context package. For documentation reasons, we decided to add NoContext to the oauth2 package. It was not a good idea even back then. And given that context package is fairly popular, there is no good reason why we are depending on this. Updating all the references of NoContext with context.Background and documenting it as deprecated. Change-Id: I18e390f1351023a29b567777a3f963dd550cf657 Reviewed-on: https://go-review.googlesource.com/27690 Reviewed-by: Chris Broadfoot <cbro@golang.org>
34 lines
990 B
Go
34 lines
990 B
Go
// Copyright 2014 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package jwt_test
|
|
|
|
import (
|
|
"context"
|
|
|
|
"golang.org/x/oauth2/jwt"
|
|
)
|
|
|
|
func ExampleJWTConfig() {
|
|
ctx := context.Background()
|
|
conf := &jwt.Config{
|
|
Email: "xxx@developer.com",
|
|
// The contents of your RSA private key or your PEM file
|
|
// that contains a private key.
|
|
// If you have a p12 file instead, you
|
|
// can use `openssl` to export the private key into a pem file.
|
|
//
|
|
// $ openssl pkcs12 -in key.p12 -out key.pem -nodes
|
|
//
|
|
// It only supports PEM containers with no passphrase.
|
|
PrivateKey: []byte("-----BEGIN RSA PRIVATE KEY-----..."),
|
|
Subject: "user@example.com",
|
|
TokenURL: "https://provider.com/o/oauth2/token",
|
|
}
|
|
// Initiate an http.Client, the following GET request will be
|
|
// authorized and authenticated on the behalf of user@example.com.
|
|
client := conf.Client(ctx)
|
|
client.Get("...")
|
|
}
|