Skip to content

Commit a563f67

Browse files
authored
Merge pull request #911 from maxkoryukov/docs/clear-auth
Make docs about auth more understandable
2 parents abfff47 + 9e219a6 commit a563f67

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

README.md

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,50 @@ new Swagger({
106106
});
107107
});
108108
```
109+
### Authorization
109110

110-
Need to pass an API key? Configure one in your client instance as a query string:
111+
Need to pass an API key? Ok, lets do it for this sample `swagger.yml`:
112+
113+
```yaml
114+
# ...
115+
116+
securityDefinitions:
117+
118+
api_sheme_name: # swagger scheme name
119+
type: apiKey # swagger type (one of "basic", "apiKey" or "oauth2")
120+
name: queryParamName # The name of the header or query parameter to be used
121+
in: query # location of the API key
122+
123+
api_sheme_name_2:
124+
type: apiKey
125+
name: X-KEY-PARAM
126+
in: header
127+
128+
# ...
129+
```
130+
131+
Configure auth for that definition in your client instance as a *query string*:
111132

112133
```js
113-
client.clientAuthorizations.add("apiKey", new Swagger.ApiKeyAuthorization("api_key","special-key","query"));
134+
client.clientAuthorizations.add("api_sheme_name",
135+
new Swagger.ApiKeyAuthorization(
136+
"queryParamName",
137+
"<YOUR-SECRET-KEY>",
138+
"query"
139+
)
140+
);
114141
```
115142

116-
...or with a header:
143+
...or with a *header*:
117144

118145
```js
119-
client.clientAuthorizations.add("apiKey", new Swagger.ApiKeyAuthorization("api_key","special-key","header"));
146+
client.clientAuthorizations.add("api_sheme_name_2",
147+
new Swagger.ApiKeyAuthorization(
148+
"X-KEY-PARAM",
149+
"<YOUR-SECRET-KEY>",
150+
"header"
151+
)
152+
);
120153
```
121154

122155
...or with the swagger-client constructor:

0 commit comments

Comments
 (0)