| 126 | } |
| 127 | |
| 128 | bool OAuthService::HandleLinkURI( |
| 129 | std::string_view uri, AudiocomTrace trace, |
| 130 | std::function<void(std::string_view)> completedHandler) |
| 131 | { |
| 132 | if (!IsPrefixedInsensitive(uri, uriPrefix)) |
| 133 | { |
| 134 | if (completedHandler) |
| 135 | completedHandler({}); |
| 136 | return false; |
| 137 | } |
| 138 | |
| 139 | // It was observed, that sometimes link is passed as audacity://link/ |
| 140 | // This is valid trace URI point of view, but we need to handle it separately |
| 141 | const auto argsStart = uri.find("?"); |
| 142 | |
| 143 | if (argsStart == std::string_view::npos) |
| 144 | { |
| 145 | if (completedHandler) |
| 146 | completedHandler({}); |
| 147 | return false; |
| 148 | } |
| 149 | |
| 150 | // Length is handled in IsPrefixed |
| 151 | auto args = uri.substr(argsStart + 1); |
| 152 | |
| 153 | std::string_view token; |
| 154 | std::string_view username; |
| 155 | std::string_view password; |
| 156 | std::string_view authorizationCode; |
| 157 | auto useAudioComRedirectURI = false; |
| 158 | |
| 159 | while (!args.empty()) |
| 160 | { |
| 161 | const auto nextArg = args.find('&'); |
| 162 | |
| 163 | const auto arg = args.substr(0, nextArg); |
| 164 | args = nextArg == std::string_view::npos ? "" : args.substr(nextArg + 1); |
| 165 | |
| 166 | if (IsPrefixed(arg, usernamePrefix)) |
| 167 | username = arg.substr(usernamePrefix.length()); |
| 168 | else if (IsPrefixed(arg, passwordPrefix)) |
| 169 | password = arg.substr(passwordPrefix.length()); |
| 170 | else if (IsPrefixed(arg, tokenPrefix)) |
| 171 | token = arg.substr(tokenPrefix.length()); |
| 172 | else if (IsPrefixed(arg, authorizationCodePrefix)) |
| 173 | { |
| 174 | //authorization code was generated for audio.com, not audacity... |
| 175 | useAudioComRedirectURI = true; |
| 176 | authorizationCode = arg.substr(authorizationCodePrefix.length()); |
| 177 | } |
| 178 | else if (IsPrefixed(arg, codePrefix)) |
| 179 | authorizationCode = arg.substr(codePrefix.length()); |
| 180 | } |
| 181 | |
| 182 | // Some browsers (safari) add an extra trailing chars we don't need |
| 183 | size_t hashPos = authorizationCode.find('#'); |
| 184 | |
| 185 | if (hashPos != std::string::npos) { |
no test coverage detected