-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Issue#6 Implement standard error
- Loading branch information
Showing
2 changed files
with
19 additions
and
14 deletions.
There are no files selected for viewing
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,26 +1,19 @@ | ||
use jwks_client::error::Error; | ||
use jwks_client::keyset::KeyStore; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let jkws_url = "https://raw.githubusercontent.com/jfbilodeau/jwks-client/0.1.8/test/test-jwks.json"; | ||
|
||
let key_set = KeyStore::new_from(jkws_url).await.unwrap(); | ||
|
||
// ... | ||
|
||
let token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjEifQ.eyJuYW1lIjoiQWRhIExvdmVsYWNlIiwiaXNzIjoiaHR0cHM6Ly9jaHJvbm9nZWFycy5jb20vdGVzdCIsImF1ZCI6InRlc3QiLCJhdXRoX3RpbWUiOjEwMCwidXNlcl9pZCI6InVpZDEyMyIsInN1YiI6InNidTEyMyIsImlhdCI6MjAwLCJleHAiOjUwMCwibmJmIjozMDAsImVtYWlsIjoiYWxvdmVsYWNlQGNocm9ub2dlYXJzLmNvbSJ9.eTQnwXrri_uY55fS4IygseBzzbosDM1hP153EZXzNlLH5s29kdlGt2mL_KIjYmQa8hmptt9RwKJHBtw6l4KFHvIcuif86Ix-iI2fCpqNnKyGZfgERV51NXk1THkgWj0GQB6X5cvOoFIdHa9XvgPl_rVmzXSUYDgkhd2t01FOjQeeT6OL2d9KdlQHJqAsvvKVc3wnaYYoSqv2z0IluvK93Tk1dUBU2yWXH34nX3GAVGvIoFoNRiiFfZwFlnz78G0b2fQV7B5g5F8XlNRdD1xmVZXU8X2-xh9LqRpnEakdhecciFHg0u6AyC4c00rlo_HBb69wlXajQ3R4y26Kpxn7HA"; | ||
let jwt = key_set.verify(token)?; | ||
let issuer = jwt.payload().iss().unwrap(); | ||
let name = jwt.payload().get_str("name").unwrap(); | ||
|
||
match key_set.verify(token) { | ||
Ok(jwt) => { | ||
let issuer = jwt.payload().iss().unwrap(); | ||
let name = jwt.payload().get_str("name").unwrap(); | ||
|
||
println!("iss={}", issuer); | ||
println!("name={}", name); | ||
} | ||
Err(Error { msg, typ: _ }) => { | ||
eprintln!("Could not verify token. Reason: {}", msg); | ||
} | ||
} | ||
println!("iss={}", issuer); | ||
println!("name={}", name); | ||
Ok(()) | ||
} |
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