microsoft / microsoft/typespec
Add parameterization to OAuth2 to support URL substitution
- Dominant language
- Java
- Stars
- 5.9k
- Forks
- 394
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 104
Description
### Clear and concise description of the problem
In order to authenticate with Firebase and other Google Services, you need to use OAuth, which is tied to a specific project, for example the following using cURL. Guide for authentication is [here](https://cloud.google.com/docs/authentication/rest)
```bash
curl -X GET \
-H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
"https://cloudresourcemanager.googleapis.com/v3/projects/PROJECT_ID"
```
We cannot specify this today for example using TypeSpec and parameterizing the `PROJECT_ID` for example where it is required, see the [send method documentation](https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages/send)
```typespec
import "@typespec/http";
using TypeSpec.Http;
@service({
title: "Firebase Cloud Messaging API",
})
@server("https://fcm.googleapis.com/v1/{PROJECT_ID}", "FCM Endpoint", {
"PROJECT_ID": string;
})
@useAuth(FirebaseOAuth)
namespace FCM;
alias FirebaseOAuth = OAuth2Auth<[{
type: OAuth2FlowType.implicit;
authorizationUrl: "https://cloudresourcemanager.googleapis.com/v3/projects/{PROJECT_ID}";
}], [
"https://www.googleapis.com/auth/firebase.messaging",
"https://www.googleapis.com/auth/cloud-platform"
]>;
```
### 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
Assessment
This issue has not been assessed yet.