Fix examples
This commit is contained in:
parent
29ad0d721d
commit
5e81d2fccb
3 changed files with 16 additions and 17 deletions
|
@ -1,14 +1,15 @@
|
||||||
extern crate crypto;
|
// need this for custom derivation
|
||||||
extern crate jwt;
|
#[macro_use]
|
||||||
extern crate rustc_serialize;
|
extern crate serde_derive;
|
||||||
|
extern crate medallion;
|
||||||
|
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use jwt::{
|
use medallion::{
|
||||||
DefaultHeader,
|
DefaultHeader,
|
||||||
Token,
|
Token,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Default, RustcDecodable, RustcEncodable)]
|
#[derive(Default, Serialize, Deserialize)]
|
||||||
struct Custom {
|
struct Custom {
|
||||||
sub: String,
|
sub: String,
|
||||||
rhino: bool,
|
rhino: bool,
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
extern crate crypto;
|
extern crate medallion;
|
||||||
extern crate jwt;
|
|
||||||
|
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use jwt::{
|
use medallion::{
|
||||||
DefaultHeader,
|
DefaultHeader,
|
||||||
Registered,
|
Registered,
|
||||||
Token,
|
Token,
|
||||||
|
@ -16,7 +15,7 @@ fn new_token(user_id: &str, password: &str) -> Option<String> {
|
||||||
|
|
||||||
let header: DefaultHeader = Default::default();
|
let header: DefaultHeader = Default::default();
|
||||||
let claims = Registered {
|
let claims = Registered {
|
||||||
iss: Some("mikkyang.com".into()),
|
iss: Some("example.com".into()),
|
||||||
sub: Some(user_id.into()),
|
sub: Some(user_id.into()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
@ -36,9 +35,9 @@ fn login(token: &str) -> Option<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let token = new_token("Michael Yang", "password").unwrap();
|
let token = new_token("Random User", "password").unwrap();
|
||||||
|
|
||||||
let logged_in_user = login(&*token).unwrap();
|
let logged_in_user = login(&*token).unwrap();
|
||||||
|
|
||||||
assert_eq!(logged_in_user, "Michael Yang");
|
assert_eq!(logged_in_user, "Random User");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
extern crate crypto;
|
extern crate medallion;
|
||||||
extern crate jwt;
|
|
||||||
|
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{Error, Read};
|
use std::io::{Error, Read};
|
||||||
use jwt::{
|
use medallion::{
|
||||||
Algorithm,
|
Algorithm,
|
||||||
DefaultHeader,
|
DefaultHeader,
|
||||||
Registered,
|
Registered,
|
||||||
|
@ -29,7 +28,7 @@ fn new_token(user_id: &str, password: &str) -> Option<String> {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let claims = Registered {
|
let claims = Registered {
|
||||||
iss: Some("mikkyang.com".into()),
|
iss: Some("example.com".into()),
|
||||||
sub: Some(user_id.into()),
|
sub: Some(user_id.into()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
@ -49,9 +48,9 @@ fn login(token: &str) -> Option<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let token = new_token("Michael Yang", "password").unwrap();
|
let token = new_token("Random User", "password").unwrap();
|
||||||
|
|
||||||
let logged_in_user = login(&*token).unwrap();
|
let logged_in_user = login(&*token).unwrap();
|
||||||
|
|
||||||
assert_eq!(logged_in_user, "Michael Yang");
|
assert_eq!(logged_in_user, "Random User");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue