|
@@ -1,4 +1,4 @@
|
|
|
-use crate::{config::Config, schema, token, UIDCError, jwt};
|
|
|
+use crate::{config::Config, jwt, schema, token, UIDCError};
|
|
|
use microrm::prelude::*;
|
|
|
use ring::signature::KeyPair;
|
|
|
|
|
@@ -14,12 +14,14 @@ pub fn create_auth_token(
|
|
|
config,
|
|
|
qi,
|
|
|
realm_id,
|
|
|
- qi.get().only_ids()
|
|
|
+ qi.get()
|
|
|
+ .only_ids()
|
|
|
.by(schema::Client::Realm, &realm_id)
|
|
|
.by(schema::Client::Shortname, client)
|
|
|
.one_id()?
|
|
|
.ok_or(UIDCError::Abort("no such client"))?,
|
|
|
- qi.get().only_ids()
|
|
|
+ qi.get()
|
|
|
+ .only_ids()
|
|
|
.by(schema::User::Realm, &realm_id)
|
|
|
.by(schema::User::Username, username)
|
|
|
.one_id()?
|
|
@@ -40,12 +42,14 @@ pub fn create_refresh_token(
|
|
|
config,
|
|
|
qi,
|
|
|
realm_id,
|
|
|
- qi.get().only_ids()
|
|
|
+ qi.get()
|
|
|
+ .only_ids()
|
|
|
.by(schema::Client::Realm, &realm_id)
|
|
|
.by(schema::Client::Shortname, client)
|
|
|
.one_id()?
|
|
|
.ok_or(UIDCError::Abort("no such client"))?,
|
|
|
- qi.get().only_ids()
|
|
|
+ qi.get()
|
|
|
+ .only_ids()
|
|
|
.by(schema::User::Realm, &realm_id)
|
|
|
.by(schema::User::Username, username)
|
|
|
.one_id()?
|
|
@@ -54,12 +58,25 @@ pub fn create_refresh_token(
|
|
|
)
|
|
|
}
|
|
|
|
|
|
-pub fn inspect_token(qi: µrm::QueryInterface, config: &Config, realm_id: schema::RealmID, token: Option<&str>) -> Result<(), UIDCError> {
|
|
|
- let key = qi.get().by(schema::Key::Realm, &realm_id).one()?.ok_or(UIDCError::Abort("no key for realm"))?;
|
|
|
+pub fn inspect_token(
|
|
|
+ qi: µrm::QueryInterface,
|
|
|
+ config: &Config,
|
|
|
+ realm_id: schema::RealmID,
|
|
|
+ token: Option<&str>,
|
|
|
+) -> Result<(), UIDCError> {
|
|
|
+ let key = qi
|
|
|
+ .get()
|
|
|
+ .by(schema::Key::Realm, &realm_id)
|
|
|
+ .one()?
|
|
|
+ .ok_or(UIDCError::Abort("no key for realm"))?;
|
|
|
|
|
|
- let kpair = ring::signature::Ed25519KeyPair::from_pkcs8(key.keydata.as_slice()).map_err(|_| UIDCError::Abort("could not load key"))?;
|
|
|
+ let kpair = ring::signature::Ed25519KeyPair::from_pkcs8(key.keydata.as_slice())
|
|
|
+ .map_err(|_| UIDCError::Abort("could not load key"))?;
|
|
|
|
|
|
- let pubkey = ring::signature::UnparsedPublicKey::new(&ring::signature::ED25519, kpair.public_key().as_ref());
|
|
|
+ let pubkey = ring::signature::UnparsedPublicKey::new(
|
|
|
+ &ring::signature::ED25519,
|
|
|
+ kpair.public_key().as_ref(),
|
|
|
+ );
|
|
|
|
|
|
let token = match token {
|
|
|
Some(token) => token.to_string(),
|
|
@@ -76,10 +93,8 @@ pub fn inspect_token(qi: µrm::QueryInterface, config: &Config, realm_id: sc
|
|
|
println!(" - expires at: {} [{}]", claims.exp, "");
|
|
|
for claim in claims.extras {
|
|
|
println!(" - {:10}: {}", claim.0, claim.1);
|
|
|
-
|
|
|
}
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
println!("Signature validation against realm key or claim parsing failed!");
|
|
|
}
|
|
|
Ok(())
|