Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MozillaVPN login (taken from MozWire) #225

Merged
merged 2 commits into from
Jun 18, 2023
Merged

Conversation

chrilves
Copy link
Contributor

Login method using API V2. Taken from MozWire. It should fix issue #210

@jamesmcm
Copy link
Owner

Thanks, it looks good could you please fix the 4 clippy issues?

error: this let-binding has unit value
  --> vopono_core/src/config/providers/mozilla/mod.rs:84:9
   |
84 | /         let _ = BASE64_URL_SAFE_NO_PAD
85 | |             .encode_string(sha2::Sha256::digest(&code_verifier), &mut code_challenge);
   | |______________________________________________________________________________________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value
   = note: `-D clippy::let-unit-value` implied by `-D warnings`
help: omit the `let` binding
   |
84 ~         BASE64_URL_SAFE_NO_PAD
85 +             .encode_string(sha2::Sha256::digest(&code_verifier), &mut code_challenge);
   |

error: the borrowed expression implements the required traits
  --> vopono_core/src/config/providers/mozilla/mod.rs:85:49
   |
85 |             .encode_string(sha2::Sha256::digest(&code_verifier), &mut code_challenge);
   |                                                 ^^^^^^^^^^^^^^ help: change this to: `code_verifier`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
   = note: `-D clippy::needless-borrow` implied by `-D warnings`

error: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let`
   --> vopono_core/src/config/providers/mozilla/mod.rs:110:17
    |
110 | /                 match code_url_regex.captures(request.url()) {
111 | |                     Some(caps) => {
112 | |                         code = caps.get(1).unwrap();
113 | |                         let response = client
...   |
124 | |                     None => (),
125 | |                 }
    | |_________________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match
    = note: `-D clippy::single-match` implied by `-D warnings`
help: try this
    |
110 ~                 if let Some(caps) = code_url_regex.captures(request.url()) {
111 +                     code = caps.get(1).unwrap();
112 +                     let response = client
113 +                         .post(&format!("{}/vpn/login/verify", Self::V2_URL))
114 +                         .header("User-Agent", "Why do you need a user agent???")
115 +                         .json(&AccessTokenRequest {
116 +                             code: code.as_str(),
117 +                             code_verifier: std::str::from_utf8(&code_verifier).unwrap(),
118 +                         })
119 +                         .send()
120 +                         .unwrap();
121 +                     return Ok(response.json::<Login>().unwrap());
122 +                 }
    |

error: the borrowed expression implements the required traits
   --> vopono_core/src/config/providers/mozilla/mod.rs:114:35
    |
114 | ...                   .post(&format!("{}/vpn/login/verify", Self::V2_URL))
    |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `format!("{}/vpn/login/verify", Self::V2_URL)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

@chrilves
Copy link
Contributor Author

Thanks, it is better?

@jamesmcm
Copy link
Owner

Thanks!

@jamesmcm jamesmcm merged commit a2f364e into jamesmcm:master Jun 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MozillaVPN - missing field login_url
2 participants