-
Notifications
You must be signed in to change notification settings - Fork 98
Looking for authorizer specification example #478
Comments
Hey @fubar, sure, here is the example:
|
Closing for now. Let me know if you have more questions. |
Thanks @mthenw, that is helpful! Am I understanding it right that authorizers can only be associated with events? If I wanted to call a function based on an HTTP request with authentication as well as based on a non-HTTP event without any authentication, I would need two different event types? I initially expected authorizers to be specified in the function definition alongside |
I took a deeper dive into this today and tried out a few things, and would like to share a few observations. Now I am aware that this project is still in its early stages and under active development, but I did not want to miss the chance to point out these things and get your thoughts and help.
eventGateway
.emit({
event: "test.foo",
data: { foo: "bar" }
}) When using eventGateway
.emit({
eventType: "test.foo",
eventTypeVersion: "1.0",
source: "/foo/bar",
contentType: "application/json",
data: {
foo: "bar"
}
}) I'd be happy to help debug further. Also, when are you planning on publishing a stable release version? Thanks! |
@fubar thanks for your feedback. ad. 1. I will look into that and let you know |
@fubar Thanks for the detailed feedback. This is really helpful. I did some digging today and found some of the root causes of your issues.
Thanks again, and feel free to reach out if you have more questions. |
Thanks for the responses @alexdebrie and @mthenw and for addressing the issues. Looking forward to further updates! |
@fubar I tested the sync / async emit behavior with the I set up two subscriptions -- an // Construct your client
const SDK = require('@serverless/event-gateway-sdk');
const eventGateway = new SDK({
url: process.env.EVENT_GATEWAY_APP_URL
})
// Test the async subscription
eventGateway.emit({
eventType: 'user.deleted',
eventTypeVersion: '1.0',
cloudEventsVersion: '0.1',
eventID: 'e58961a5-f53b-4849-8ae5-cb06c031919e',
source: '/services/users',
contentType: 'application/json',
data: {
userID: 123
}
}).then(res => console.log(res.status))
// Test the sync subscription
eventGateway.emit({
eventID: '1',
eventType: 'user.created',
cloudEventsVersion: '0.1',
source: '/services/users',
contentType: 'application/json',
data: {
userID: 'foo'
}
}).then(res => res.json())
.then(json => console.log(json)) The first one returns immediately with a 202 status code and an empty body. The second one returns with a 200 status code and the response from my Lambda function. In the collapsed sections below, I have my Let me know if that solves your problem! I'll keep this ticket open until you give the sign off 👌. serverless.yml# serverless.yml
service: event-gateway-auth
plugins:
- "@serverless/serverless-event-gateway-plugin"
custom:
eventgateway:
url: ${env:EVENT_GATEWAY_APP_URL}
accessKey: ${env:EVENT_GATEWAY_ACCESS_KEY}
eventTypes:
user.created:
authorizer: auth
user.deleted:
provider:
name: aws
runtime: python3.6
stage: dev
region: us-east-1
functions:
auth:
handler: handler.auth
main:
handler: handler.main
events:
- eventgateway:
type: sync
eventType: user.created
path: /
cors: true
delete:
handler: handler.main
events:
- eventgateway:
type: async
eventType: user.deleted
path: /
cors: true handler.py# handler.py
import json
def auth(event, context):
print(event)
body = {
"message": "Go Serverless v1.0! Your function executed successfully!",
"input": event
}
response = {
"authorization": {
"principalId": "user123",
"context": {
"name": "Bill Gates"
}
}
}
return response
def main(event, context):
print(event)
body = {
"message": "Go Serverless v1.0! Your function executed successfully!",
"input": event
}
response = {
"statusCode": 200,
"body": json.dumps(body)
}
return response |
@alexdebrie Edit |
Hi, |
Hey @johnlim, sorry to hear that. I just tested a few times and it worked for me. Can you share the following things:
Thanks! |
Hi @alexdebrie thanks for looking into this.
My current use case though is to do auth on |
Hi @alexdebrie, were you able to duplicate this? Do let me know if you need any further info. Cheers. |
@alexdebrie Thanks for the fix! I've verified that it fixes the aforementioned issue. Really appreciate it |
@alexdebrie If I understand correctly, the current design for authorizers on http requests require them to be tied to
If so, how would I declare a public http endpoint if I also need to declare some private ones (i.e with authorizer functions)?
Any update on this? Thanks. |
@alexdebrie Are there use cases for multiple subscribers to a single http event? If not, instead of supporting authorizers on subscribers of
and have the http endpoints emit events, if needed. Not only does this save development effort but also makes it easy to setup custom domains for the endpoints. That does however bring up a big security question. Based on my understanding, it seems that anyone who knows your Event Gateway url, will be able to emit events. For example, by using the |
@alexdebrie @mthenw |
Hey @johnlim, great question. While the Event Gateway does allow for REST-like HTTP endpoints, it's really intended to be an event router more than a traditional API Gateway. As such, it's not as full-featured in the API Gateway department, such as allowing for granular authorization strategies on different endpoints. We may add this functionality in the future but are presently focused on more event-driven flows. Does that help? |
Hi @alexdebrie,
|
Hey guys, |
I'm in the process of evaluating this project for our API. It looks promising, but one core aspect is unclear to me.
Could you provide an example of how I would specify/reference an authorizer function in
serverless.yml
?Thanks!
The text was updated successfully, but these errors were encountered: