|
10 | 10 | #include "nmos/json_schema.h" |
11 | 11 | #include "nmos/json_fields.h" |
12 | 12 | #include "nmos/slog.h" |
13 | | -#if defined(_WIN32) && !defined(__cplusplus_winrt) |
14 | | -#include <Windows.h> |
15 | | -#include <shellapi.h> |
16 | | -#endif |
17 | 13 |
|
18 | 14 | namespace nmos |
19 | 15 | { |
@@ -181,29 +177,28 @@ namespace nmos |
181 | 177 | }; |
182 | 178 | } |
183 | 179 |
|
184 | | - // construct callback to start the authorization code flow request on a browser |
| 180 | + // construct callback to start the authorization code grant flow request |
185 | 181 | // this is required for OAuth clients which use Authorization Code Flow to obtain the access token |
186 | | - // note: as it is not easy to specify the 'content-type' used in the browser programmatically, this can be easily |
187 | | - // fixed by installing a browser header modifier |
188 | | - // extensions such as ModHeader can be used to add the missing 'content-type' header: |
189 | | - // for Windows https://chrome.google.com/webstore/detail/modheader-modify-http-hea/idgpnmonknjnojddfkpgkljpfnnfcklj |
190 | | - // for Linux https://addons.mozilla.org/en-GB/firefox/addon/modheader-firefox/ |
191 | | - request_authorization_code_handler make_request_authorization_code_handler(slog::base_gate& gate) |
| 182 | + // this implementation does not launch a browser (or any other external process) itself - it simply logs |
| 183 | + // the uri the user needs to visit to grant authorization, at warning severity so that it's visible by default |
| 184 | + // applications that want to automatically open a browser should supply their own handler via |
| 185 | + // node_implementation::on_request_authorization_code, e.g. one which launches the platform's browser directly |
| 186 | + // (not via a command shell) with the uri as a single argument, to avoid the possibility of command/shell injection |
| 187 | + // note: the authorization_code_uri consists of the authorization endpoint, client_id, redirect_uri, scope and state parameters etc |
| 188 | + // see https://specs.amwa.tv/is-10/latest/Behaviour%20-%20Token%20Requests/#authorization-request-and-response |
| 189 | + // see https://tools.ietf.org/html/rfc6749#section-4.1 |
| 190 | + // see https://github.com/sony/nmos-cpp/blob/master/Documents/Authorization.md#authorization-code-grant |
| 191 | + // note: as it is not easy to specify the 'content-type' used in the browser programmatically; this can be easily fixed |
| 192 | + // by installing a browser header modifier extension such as ModHeader, which can be used to add the missing 'content-type' header. |
| 193 | + nmos::experimental::request_authorization_code_handler make_request_authorization_code_handler(slog::base_gate& gate) |
192 | 194 | { |
193 | 195 | return[&gate](const web::uri& authorization_code_uri) |
194 | 196 | { |
195 | | - slog::log<slog::severities::more_info>(gate, SLOG_FLF) << "Open a browser to start the authorization code flow: " << authorization_code_uri.to_string(); |
196 | | - |
197 | | - std::string browser_cmd; |
198 | | -#if defined(_WIN32) && !defined(__cplusplus_winrt) |
199 | | - browser_cmd = "start \"\" \"" + utility::us2s(authorization_code_uri.to_string()) + "\""; |
200 | | -#else |
201 | | - browser_cmd = "xdg-open \"" + utility::us2s(authorization_code_uri.to_string()) + "\""; |
202 | | -#endif |
203 | | - std::ignore = system(browser_cmd.c_str()); |
| 197 | + slog::log<slog::severities::warning>(gate, SLOG_FLF) << "Open a browser and visit the following URI to start the authorization code flow: " << authorization_code_uri.to_string(); |
204 | 198 |
|
205 | | - // hmm, notify authorization_code_flow in the authorization_behaviour thread |
206 | | - // in the event of user cancels the authorization code flow process |
| 199 | + // The authorization code flow process (obtaining the access token) is expected to be completed within the time specified in the settings; |
| 200 | + // otherwise, the authorization code flow process will be considered failed |
| 201 | + // See authorization_code_flow_max in settings.h |
207 | 202 | }; |
208 | 203 | } |
209 | 204 |
|
|
0 commit comments