You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/03-tools/03-openapi.md
+68-8Lines changed: 68 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -40,16 +40,76 @@ Will be resolved as `https://api.example.com/v1`.
40
40
41
41
## Authentication
42
42
43
-
GPTScript currently ignores any security schemes and authentication/authorization information in the OpenAPI definition file. This might change in the future.
43
+
:::warning
44
+
All authentication options will be completely ignored if the server uses HTTP and not HTTPS.
45
+
This is to protect users from accidentally sending credentials in plain text.
46
+
:::
44
47
45
-
For now, the only supported type of authentication is bearer tokens. GPTScript will look for a special environment variable based
46
-
on the hostname of the server. It looks for the format `GPTSCRIPT_<HOST>_BEARER_TOKEN`, where `<HOST>` is the hostname, but in all caps and
47
-
dots are replaced by underscores. For example, if the server is `https://api.example.com`, GPTScript will look for an environment variable
48
-
called `GPTSCRIPT_API_EXAMPLE_COM_BEARER_TOKEN`. If it finds one, it will use it as the bearer token for all requests to that server.
48
+
### 1. Security Schemes
49
49
50
-
:::note
51
-
GPTScript will not look for bearer tokens if the server uses HTTP instead of HTTPS.
52
-
:::
50
+
GPTScript will read the defined [security schemes](https://swagger.io/docs/specification/authentication/) in the OpenAPI definition. The currently supported types are `apiKey` and `http`.
51
+
OAuth and OIDC schemes will be ignored.
52
+
53
+
GPTScript will look at the `security` defined on the operation (or defined globally, if it is not defined on the operation) before it makes the request.
54
+
It will set the necessary headers, cookies, or query parameters based on the corresponding security scheme.
55
+
56
+
Environment variables must be set for each security scheme that will be used by the operation.
57
+
`<HOSTNAME>`is the hostname of the server, but all caps, and with dashes (`-`) and dots (`.`) replaced with underscores (`_`).
58
+
`<SCHEME NAME>`is the name of the security scheme, but all caps, and with dashes (`-`) and dots (`.`) replaced with underscores (`_`).
59
+
60
+
- For `apiKey`-type and `http`-type with `bearer` scheme, the environment variable is `GPTSCRIPT_<HOSTNAME>_<SCHEME NAME>`
61
+
- For `http`-type with `basic` scheme, the environment variables are `GPTSCRIPT_<HOSTNAME>_<SCHEME NAME>_USERNAME` and `GPTSCRIPT_<HOSTNAME>_<SCHEME NAME>_PASSWORD`
62
+
63
+
#### Example
64
+
65
+
To explain this better, let's use this example:
66
+
67
+
```yaml
68
+
servers:
69
+
- url: https://api.example.com/v1
70
+
components:
71
+
securitySchemes:
72
+
MyBasic:
73
+
type: http
74
+
scheme: basic
75
+
76
+
MyAPIKey:
77
+
type: apiKey
78
+
in: header
79
+
name: X-API-Key
80
+
security:
81
+
- MyBasic: []
82
+
- MyAPIKey: []
83
+
# The rest of the document defines paths, etc.
84
+
```
85
+
86
+
In this example, we have two security schemes, and both are defined as the defaults on the global level.
87
+
They are separate entries in the global `security` array, so they are treated as a logical OR, and GPTScript will only
88
+
need the environment variable for one or the other to make the request.
89
+
90
+
When put into the same entry, they would be a logical AND, and the environment variables for both would be required.
91
+
It would look like this:
92
+
93
+
```yaml
94
+
security:
95
+
- MyBasic: []
96
+
MyAPIKey: []
97
+
```
98
+
99
+
The environment variable names are as follows:
100
+
101
+
- `GPTSCRIPT_API_EXAMPLE_COM_MYBASIC_USERNAME`and `GPTSCRIPT_API_EXAMPLE_COM_MYBASIC_PASSWORD` for basic auth
102
+
- `GPTSCRIPT_API_EXAMPLE_COM_MYAPIKEY`for the API key
103
+
104
+
### 2. Bearer token for server
105
+
106
+
GPTScript can also use a bearer token for all requests to a particular server that don't already have an `Authorization` header.
107
+
To do this, set the environment variable `GPTSCRIPT_<HOSTNAME>_BEARER_TOKEN`.
108
+
If a request to the server already has an `Authorization` header, the bearer token will not be added.
109
+
110
+
This can be useful in cases of unsupported auth types. For example, GPTScript does not have built-in support for OAuth,
111
+
but you can go through an OAuth flow, get the access token, and set it to the environment variable as a bearer token
0 commit comments