diff --git a/examples/github.rs b/examples/github.rs new file mode 100644 index 0000000..9f5624d --- /dev/null +++ b/examples/github.rs @@ -0,0 +1,15 @@ +extern crate inth_oauth2; + +use inth_oauth2::Client; + +fn main() { + let client = Client::github( + "01774654cd9a6051e478", + "9f14d16d95d605e715ec1a9aecec220d2565fd5c", + Some("https://cmcenroe.me/oauth2-paste") + ); + + let auth_uri = client.auth_uri(Some("user"), None).unwrap(); + + println!("{}", auth_uri); +} diff --git a/src/lib.rs b/src/lib.rs index c573fd0..57a8850 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,6 +47,22 @@ impl Client { } } + /// Creates a GitHub OAuth 2.0 client. + pub fn github>( + client_id: S, + client_secret: S, + redirect_uri: Option + ) -> Self { + Client { + auth_uri: String::from("https://github.com/login/oauth/authorize"), + token_uri: String::from("https://github.com/login/oauth/access_token"), + + client_id: client_id.into(), + client_secret: client_secret.into(), + redirect_uri: redirect_uri.map(Into::::into), + } + } + /// Constructs an authorization request URI. pub fn auth_uri(&self, scope: Option<&str>, state: Option<&str>) -> ParseResult { let mut uri = try!(Url::parse(&self.auth_uri));