Struct safe_api::SafeAuthenticator [−][src]
Implementations
impl SafeAuthenticator
[src]
pub fn new(config_dir_path: Option<&str>) -> Self
[src]
pub async fn log_in(&mut self, passphrase: &str, password: &str) -> Result<()>
[src]
Log in
Using an account already created, you can log in to
the SAFE Network using the Authenticator
daemon.
Example
use safe_api::SafeAuthenticator; let mut safe_auth = SafeAuthenticator::new(None); /// Using an already existing account's passphrase and password: let my_secret = "mysecretstring"; let my_password = "mypassword"; let logged_in = safe_auth.log_in(my_secret, my_password).await; match logged_in { Ok(()) => assert!(true), // This should pass Err(_) => assert!(false) }
Error Example
If the account does not exist, the function will return an appropriate error:
use safe_api::{SafeAuthenticator, Error}; let mut safe_auth = SafeAuthenticator::new(None); let not_logged_in = safe_auth.log_in("non", "existant").await; match not_logged_in { Ok(()) => assert!(false), // This should not pass Err(Error::AuthError(message)) => { assert!(message.contains("Failed to log in")); } Err(_) => assert!(false), // This should not pass }
pub fn log_out(&mut self) -> Result<()>
[src]
pub fn is_logged_in(&self) -> bool
[src]
pub async fn create_acc(
&mut self,
sk: &str,
passphrase: &str,
password: &str
) -> Result<()>
[src]
&mut self,
sk: &str,
passphrase: &str,
password: &str
) -> Result<()>
Create Account
Creates a new account on the SAFE Network. Returns an error if an account exists or if there was some problem during the account creation process. If the account is successfully created it keeps the logged in session (discarding a previous session)
Note: This does not perform any strength checks on the strings used to create the account.
Example
use safe_api::SafeAuthenticator; let mut safe_auth = SafeAuthenticator::new(None); let my_secret = "mysecretstring"; let my_password = "mypassword"; let acc_created = safe_auth.create_acc(sk, my_secret, my_password).await; match acc_created { Ok(()) => assert!(true), // This should pass Err(_) => assert!(false) }
Error Example
If an account with same passphrase already exists, the function will return an error:
use safe_api::{SafeAuthenticator, Error}; let mut safe_auth = SafeAuthenticator::new(None); /// Using an already existing account's passphrase and password: let my_secret = "mysecretstring"; let my_password = "mypassword"; let acc_not_created = safe_auth.create_acc(sk, my_secret, my_password).await; match acc_not_created { Ok(_) => assert!(false), // This should not pass Err(Error::AuthError(message)) => { assert!(message.contains("Failed to create an account")); } Err(_) => assert!(false), // This should not pass }
pub async fn decode_req(
&self,
req: &str
) -> Result<(SafeAuthReqId, SafeAuthReq)>
[src]
&self,
req: &str
) -> Result<(SafeAuthReqId, SafeAuthReq)>
pub async fn authorise_app(&self, req: &str) -> Result<String>
[src]
Authorise an application
Using an account already created, you can log in to the SAFE Network and authorise an application.
Example
use safe_api::SafeAuthenticator; let mut safe_auth = SafeAuthenticator::new(None); /// Using an already existing account's passphrase and password: let my_secret = "mysecretstring"; let my_password = "mypassword"; let auth_req = "bAAAAAAEXVK4SGAAAAAABAAAAAAAAAAAANZSXILTNMFUWI43BMZSS4Y3MNEAAQAAAAAAAAAAAKNAUMRJAINGESEAAAAAAAAAAABGWC2LEKNQWMZJONZSXIICMORSAAAIBAAAAAAAAAAAAOAAAAAAAAAAAL5YHKYTMNFRQCAAAAAAAAAAAAAAAAAAB"; safe_auth.log_in(my_secret, my_password).await.unwrap(); let auth_response = safe_auth.authorise_app(auth_req/*, &|_| true*/).await; match auth_response { Ok(_) => assert!(true), // This should pass Err(_) => assert!(false) }
Error Example
use safe_api::{SafeAuthenticator, Error}; let mut safe_auth = SafeAuthenticator::new(None); /// Using an already existing account's passphrase and password: let my_secret = "mysecretstring"; let my_password = "mypassword"; /// Using an invalid auth request string let auth_req = "invalid-auth-req-string"; safe_auth.log_in(my_secret, my_password).await.unwrap(); let auth_response = safe_auth.authorise_app(auth_req/*, &|_| true*/).await; match auth_response { Ok(_) => assert!(false), // This should not pass Err(Error::AuthError(message)) => { assert!(message.contains("EncodeDecodeError")); } Err(_) => assert!(false), // This should not pass }
pub async fn authed_apps(&self) -> Result<AuthedAppsList>
[src]
Get the list of applications authorised by this account
Using an account already created, you can log in to the SAFE Network and get the list of all the applications that have been authorised so far.
Example
use safe_api::SafeAuthenticator; let mut safe_auth = SafeAuthenticator::new(None); /// Using an already existing account which has been /// already used to authorise some application: let my_secret = "mysecretstring"; let my_password = "mypassword"; safe_auth.log_in(my_secret, my_password).await.unwrap(); /// Get the list of authorised apps let authed_apps = safe_auth.authed_apps().await; match authed_apps { Ok(_) => assert!(true), // This should pass Err(_) => assert!(false) }
pub async fn revoke_app(&self, app_id: &str) -> Result<()>
[src]
Revoke all permissions from an application
Using an account already created, you can log in to the SAFE Network and revoke all permissions previously granted to an application by providing its ID.
Example
use safe_api::SafeAuthenticator; let mut safe_auth = SafeAuthenticator::new(None); /// Using an already existing account which has been /// already used to authorise some application: let my_secret = "mysecretstring"; let my_password = "mypassword"; safe_auth.log_in(my_secret, my_password).await.unwrap(); /// Revoke all permissions from app with ID `net.maidsafe.cli` let revoked = safe_auth.revoke_app("net.maidsafe.cli").await; match revoked { Ok(_) => assert!(true), // This should pass Err(_) => assert!(false) }
Error Example
use safe_api::{SafeAuthenticator, Error}; let mut safe_auth = SafeAuthenticator::new(None); /// Using an already existing account which has been /// already used to authorise some application: let my_secret = "mysecretstring"; let my_password = "mypassword"; safe_auth.log_in(my_secret, my_password).await.unwrap(); /// Try to revoke permissions with an incorrect app ID let revoked = safe_auth.revoke_app("invalid-app-id").await; match revoked { Ok(_) => assert!(false), // This should not pass Err(Error::AuthError(message)) => { assert!(message.contains("UnknownApp")); } Err(_) => assert!(false), // This should not pass }
Trait Implementations
impl Default for SafeAuthenticator
[src]
fn default() -> SafeAuthenticator
[src]
Auto Trait Implementations
impl !RefUnwindSafe for SafeAuthenticator
[src]
impl Send for SafeAuthenticator
[src]
impl Sync for SafeAuthenticator
[src]
impl Unpin for SafeAuthenticator
[src]
impl !UnwindSafe for SafeAuthenticator
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Clear for T where
T: InitializableFromZeroed + ?Sized,
T: InitializableFromZeroed + ?Sized,
pub fn clear(&mut self)
impl<T> From<T> for T
[src]
impl<T> InitializableFromZeroed for T where
T: Default,
T: Default,
pub unsafe fn initialize(place: *mut T)
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> UnsafeAny for T where
T: Any,
T: Any,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,