Comments (5)
Turns out this was our fault. The Audience value was not being passed in correctly - we were actually getting an empty string. Now that it's being set to the correct client ID value, the AuthorizationHeader
does work to authenticate the task. Thanks for the help @codyoss!
from go-genproto.
Hmmm that looks very similar to what I did. My value for Audience in your case would have been "www.urlgoeshere.com"
. I posted to a URL(HTTP Cloud Function) and verified I had an Authorization header in the incoming request. I am not an expert on this API though. I would suggest reaching out to the Cloud Task Support for issues related specifically to this API.
from go-genproto.
I was able to use that sample and it worked for me. There are a couple things through. Make sure you have the correct IAM perms set up as described in the docs for the AuthorizationHeader type you are using. I used an OidcToken and I also provided the audience field to match the url. Hope that helps.
from go-genproto.
@codyoss - thanks for your response. I may not have been specific enough about the code I'm using. I'm attaching a simplified version of the code below - also see the Go Playground link ( https://go.dev/play/p/Ec38d2CAcBa ):
package main
import (
"context"
"time"
cloudtasks "cloud.google.com/go/cloudtasks/apiv2"
taskspb "google.golang.org/genproto/googleapis/cloud/tasks/v2"
"google.golang.org/protobuf/types/known/timestamppb"
)
func main() {
// simplified version of code:
ctx := context.Background()
taskRequest := taskspb.CreateTaskRequest{
Parent: "queue-name-goes-here",
Task: &taskspb.Task{
ScheduleTime: timestamppb.New(time.Now()), // optional time
MessageType: &taskspb.Task_HttpRequest{
HttpRequest: &taskspb.HttpRequest{
HttpMethod: taskspb.HttpMethod_POST,
Url: "www.urlgoeshere.com",
AuthorizationHeader: &taskspb.HttpRequest_OidcToken{
OidcToken: &taskspb.OidcToken{
ServiceAccountEmail: "[email protected]",
Audience: "project_number-number_generated_by_iap.apps.googleusercontent.com",
},
},
},
},
},
}
client, _ := cloudtasks.NewClient(ctx)
task, err := client.CreateTask(ctx, &taskRequest)
// etc.
}
The IAM permissions for the service account we're using include everything listed here: https://cloud.google.com/tasks/docs/creating-http-target-tasks#sa
That is, two of its roles are Cloud Tasks Enqueuer and Service Account User.
The Audience
value we're using is an OAuth 2.0 client ID listed on this page - https://console.cloud.google.com/apis/credentials for our project.
We also tried using the task url (from the Url
field) as the audience but this didn't make a difference. The auth header did not get attached in either case. Any idea why?
from go-genproto.
@michal-wknd Glad to hear it, np!
from go-genproto.
Related Issues (20)
- Adding googleads API HOT 2
- add ai/generativelanguage types HOT 6
- Eliminate use of alias field_mask package HOT 3
- onboard onto owlbot
- [Policy Bot] found one or more issues with this repository. HOT 1
- New submodules: upgrade before 2024-03-01 to avoid ambiguous import errors with google.golang.org/genproto HOT 4
- [Policy Bot] found one or more issues with this repository. HOT 1
- Please generate these files with google.golang.org/grpc/cmd/protoc-gen-go-grpc HOT 5
- Licence examples causing hits on FOSSA.com HOT 3
- Cannot get genproto HOT 4
- Missing SearchRelatedAccountGroupMembershipsRequest.GetParent() implementation. HOT 2
- ci: reenable apidiff workflow once multi-package execution is fixed
- ci: Skip apidiff for newly added packages
- Unable to unmarshal `Document` due to orientation is outputted as string `PAGE_UP` HOT 7
- update go.mod to 1.17
- Use of the repo not clear HOT 1
- Add support for Datastore COUNT (aggregation) query HOT 1
- Different types between this repo and Bazel HOT 1
- go build should run all versions, not just latest HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-genproto.