microsoft / microsoft/typespec

Allow for scopes when using ApiKeyAuth to support AWS API Gateway & Cognito

Open
#5,181 2 comments 2 reactions 0 assignees View on GitHub
design:needed lib:http needs-area triaged:core
Dominant language
Java
Stars
5.9k
Forks
394
Avg merge
1d 23h
Merged PRs (30d)
104

Description

### Clear and concise description of the problem

Goal: Create a way to use AWS API Gateway with Cognito as an authorizer, and define scopes.

I believe this is currently not possible as you cannot pass in scopes with ApiKeyAuth which is what AWS expects.

Something like

```tsp
@extension("x-amazon-apigateway-authtype", "cognito_user_pools")
@extension("x-amazon-apigateway-authorizer", {
type: "cognito_user_pools",
providerARNs: ["arn:"],
})
model CognitoAuth is ApiKeyAuth;

@post
@extension("x-amazon-apigateway-integration", {
type: "http_proxy",
httpMethod: "post",
uri: "http://",
connectionId: vpcLinkId,
connectionType: "VPC_LINK",
})
@useAuth(CognitoAuth)
post(CreateUser): {
@statusCode statusCode: 201;
@body _: User;
};
```

Example output:

```yaml
post:
...
security:
- CognitoAuth:
- "users/:write"
x-amazon-apigateway-integration:
connectionId: ""
httpMethod: "GET"
uri: ""
responses:
default:
statusCode: "201"
connectionType: "VPC_LINK"
...
securitySchemes:
CognitoAuth:
type: "apiKey"
name: "Authorization"
in: "header"
x-amazon-apigateway-authtype: "cognito_user_pools"
x-amazon-apigateway-authorizer:
providerARNs:
- "arn:
type: "cognito_user_pools"
```

See https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-enable-cognito-user-pool.html

### Checklist

- [x] Follow our [Code of Conduct](https://github.com/microsoft/typespec/blob/main/CODE_OF_CONDUCT.md)
- [x] Read the [docs](https://typespec.io/docs/).
- [x] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.