-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add urlencoding crate and update dependencies
- Loading branch information
Showing
5 changed files
with
113 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,22 @@ | ||
use wasm_bindgen::prelude::*; | ||
|
||
use super::linkedin; | ||
|
||
#[wasm_bindgen] | ||
struct AuthApi { | ||
linkedin: LinkedInApi, | ||
#[derive(Clone, Debug, PartialEq)] | ||
pub struct AuthApi { | ||
linkedin: Option<linkedin::Api>, | ||
} | ||
|
||
#[wasm_bindgen] | ||
struct LinkedInApi; | ||
impl AuthApi { | ||
#[wasm_bindgen(constructor)] | ||
pub fn new(linkedin: Option<linkedin::Api>) -> Self { | ||
Self { linkedin } | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn linkedin(self) -> linkedin::Api { | ||
self.linkedin.expect("LinkedIn API is not available") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen] | ||
#[derive(Clone, Debug, PartialEq)] | ||
pub struct Api { | ||
client_id: String, | ||
redirect_uri: String, | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl Api { | ||
#[wasm_bindgen(constructor)] | ||
pub fn new(client_id: &str, redirect_uri: &str) -> Self { | ||
Self { | ||
client_id: client_id.to_string(), | ||
redirect_uri: redirect_uri.to_string(), | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn sign_in(&self) -> String { | ||
self.sign_in_with_params(SignInParams::new()) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn sign_in_with_params(&self, params: SignInParams) -> String { | ||
let scopes = params | ||
.scopes | ||
.iter() | ||
.map(|scope| scope.to_string()) | ||
.collect::<Vec<String>>() | ||
.join(" "); | ||
|
||
format!("https://www.linkedin.com/oauth/v2/authorization?response_type={}&client_id={}&redirect_uri={}&scope={}", ¶ms.response_type, &self.client_id, urlencoding::encode(&self.redirect_uri), urlencoding::encode(&scopes)) | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub struct SignInParams { | ||
response_type: Responsetype, | ||
scopes: Vec<Scope>, | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl SignInParams { | ||
#[wasm_bindgen(constructor)] | ||
pub fn new() -> Self { | ||
Self { | ||
response_type: Responsetype::Code, | ||
scopes: vec![Scope::Openid, Scope::Profile, Scope::Email], | ||
} | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub enum Responsetype { | ||
Code, | ||
} | ||
|
||
impl std::fmt::Display for Responsetype { | ||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
match self { | ||
Responsetype::Code => write!(f, "code"), | ||
} | ||
} | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub enum Scope { | ||
Openid, | ||
Profile, | ||
Email, | ||
} | ||
|
||
impl std::fmt::Display for Scope { | ||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
match self { | ||
Scope::Openid => write!(f, "openid"), | ||
Scope::Profile => write!(f, "profile"), | ||
Scope::Email => write!(f, "email"), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
pub mod api; | ||
mod api; | ||
pub mod linkedin; | ||
|
||
pub use api::AuthApi; |