gcp

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2022 License: Apache-2.0 Imports: 23 Imported by: 9

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var Scopes = []string{
	"openid",
	"https://www.googleapis.com/auth/userinfo.email",
	"https://www.googleapis.com/auth/cloud-platform",
	"https://www.googleapis.com/auth/compute",
	"https://www.googleapis.com/auth/accounts.reauth",
}

Scopes defines default auth scopes

Functions

func JwtClaims

func JwtClaims(ctx context.Context, tokenString string) (*sjwt.Claims, error)

JwtClaims extract token info, but it does not verify token

Types

type Client

type Client struct {
	ID     string
	Secret string
	App    string
}

Client represents IAM GCP client

func (*Client) Config

func (c *Client) Config(redirectURL string, scopes ...string) *oauth2.Config

Config creates oauth config

type Service

type Service struct {
	// contains filtered or unexported fields
}

func New

func New(client *Client) *Service

func (*Service) Auth

func (s *Service) Auth(ctx context.Context, scopes ...string) (*auth.Token, error)

func (*Service) AuthClient

func (s *Service) AuthClient(ctx context.Context, scopes ...string) (*http.Client, error)

AuthClient returns auth HTTP client

func (*Service) Config

func (s *Service) Config(ctx context.Context, scopes ...string) *oauth2.Config

func (*Service) IDClient

func (s *Service) IDClient(ctx context.Context, audience string, scopes ...string) (*http.Client, error)

IDClient returns identity token HTTP client

Example
package main

import (
	"context"
	"fmt"
	"github.com/viant/scy/auth/gcp"
	"github.com/viant/scy/auth/gcp/client"
	"io/ioutil"
	"log"
)

func main() {
	srv := gcp.New(client.NewScy())
	ctx := context.Background()
	audience := "https://us-central1-myProject.cloudfunctions.net/MyCloudFunction"
	httpClient, err := srv.IDClient(ctx, audience)
	//Call secured cloud function
	resp, err := httpClient.Get(audience)
	if err != nil {
		log.Fatal(err)
	}
	data, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("CF response: %s\n", data)
}
Output:

func (*Service) IDToken

func (s *Service) IDToken(ctx context.Context, audience string, scopes ...string) (*oauth2.Token, error)

func (*Service) TokenSource

func (s *Service) TokenSource(scopes ...string) oauth2.TokenSource

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL