-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from jbertovic/develop
Integrated auth module from tdamertiradeclient
- Loading branch information
Showing
7 changed files
with
286 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
[package] | ||
name = "tdacli" | ||
version = "0.1.0" | ||
version = "0.2.0" | ||
authors = ["Jas Bertovic <[email protected]>"] | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
tdameritradeclient = { git = "https://github.com/jbertovic/tdameritradeclient.git", tag = "v0.1.1" } | ||
tdameritradeclient = { git = "https://github.com/jbertovic/tdameritradeclient.git", tag = "v0.2.1" } | ||
clap = "2.33" |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use clap::ArgMatches; | ||
use tdameritradeclient::auth::{getcodeweblink, gettoken_fromrefresh, getrefresh_fromrefresh, TDauth}; | ||
|
||
/// Create a link to use to get an authorization_code from tdameritrade | ||
/// Code can be used to fetch a token and refresh token in the `auth` subcommand | ||
pub fn weblink(args: &ArgMatches) { | ||
println!("{}", | ||
getcodeweblink(args.value_of("clientid").unwrap(), args.value_of("redirect").unwrap())); | ||
} | ||
/// Fetch updated `token` or `refresh_token` from a current `refresh_token` | ||
pub fn auth(args: &ArgMatches, code: String) { | ||
match args.value_of("clientid") { | ||
Some(clientid) => { | ||
match args.value_of("redirect") { | ||
Some(redirect) => { | ||
let decoded = !args.is_present("decoded"); | ||
let tdauth = TDauth::new_fromcode(&code, clientid, redirect, decoded); | ||
let (t, r) = tdauth.gettokens(); | ||
println!("{{\"Token\": \"{}\", \"Refresh\": \"{}\"}}", t, r) | ||
}, | ||
None => println!("{{ \"error\": \"Missing redirect\"}}"), | ||
} | ||
}, | ||
None => println!("{{ \"error\": \"Missing clientid\"}}"), | ||
} | ||
} | ||
/// Fetch updated `token` or `refresh_token` from a current `refresh_token` | ||
pub fn refresh(args: &ArgMatches, rtoken: String) { | ||
match args.value_of("clientid") { | ||
Some(clientid) => { | ||
// do i need to renew refresh or only token? | ||
// need to update tdameritradeclient to include getrefresh_fromrefresh() | ||
let token = if args.is_present("updaterefresh") { | ||
gettoken_fromrefresh(&rtoken, clientid) | ||
} else { | ||
getrefresh_fromrefresh(&rtoken, clientid) | ||
}; | ||
println!("{}", token); | ||
} | ||
None => println!("{{ \"error\": \"Missing clientid\"}}"), | ||
} | ||
} |
Oops, something went wrong.