identity-toolkit-go-client 是 Go 语言环境中的 Google identity Toolkit 客户端库。
示例:
var client *gitkit.Client func handleSignIn(w http.ResponseWriter, r *http.Request) { // If there is no valid session, check identity tookit ID token. ts := client.TokenFromRequest(r) token, err := client.ValidateToken(ts) if err != nil { // Not a valid token. Handle error. } // Token is validate and it contains the user account information // including user ID, email address, etc. // Issue your own session cookie to finish the sign in. } func main() { // Provide configuration. gitkit.LoadConfig() can also be used to load // the configuration from a JSON file. config := &gitkit.Config{ ClientID: "123.apps.googleusercontent.com", WidgetURL: "http://localhost/gitkit", ServerAPIKey: "server_api_key", ServiceAccount: "123-abc@developer.gserviceaccount.com", PEMKeyPath: "/path/to/service_account/private-key.pem", } var err error client, err = gitkit.New(config) if err != nil { // Handle error. } // Provide HTTP handler. http.HandleFunc("/signIn", handleSignIn) // Start the server. log.Fatal(http.ListenAndServe(":8080", nil)) }