[−][src]Struct safe_api::SafeAuthenticator
Methods
impl SafeAuthenticator
[src]
pub fn new(config_dir_path: Option<&str>) -> Self
[src]
pub 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); 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"); 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 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); 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); 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 fn decode_req(&self, req: &str) -> Result<(SafeAuthReqId, SafeAuthReq)>
[src]
pub 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).unwrap(); let auth_response = safe_auth.authorise_app(auth_req/*, &|_| true*/); 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).unwrap(); let auth_response = safe_auth.authorise_app(auth_req/*, &|_| true*/); 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 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 used /// to authorise some application already: let my_secret = "mysecretstring"; let my_password = "mypassword"; safe_auth.log_in(my_secret, my_password).unwrap(); /// Get the list of authorised apps let authed_apps = safe_auth.authed_apps(); match authed_apps { Ok(_) => assert!(true), // This should pass Err(_) => assert!(false) }
pub 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 used /// to authorise some application already: let my_secret = "mysecretstring"; let my_password = "mypassword"; safe_auth.log_in(my_secret, my_password).unwrap(); /// Revoke all permissions from app with ID `net.maidsafe.cli` let revoked = safe_auth.revoke_app("net.maidsafe.cli"); 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 used /// to authorise some application already: let my_secret = "mysecretstring"; let my_password = "mypassword"; safe_auth.log_in(my_secret, my_password).unwrap(); /// Try to revoke permissions with an incorrect app ID let revoked = safe_auth.revoke_app("invalid-app-id"); 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
impl Send for SafeAuthenticator
impl Sync for SafeAuthenticator
impl Unpin for SafeAuthenticator
impl !UnwindSafe for SafeAuthenticator
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,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Clear for T where
T: InitializableFromZeroed + ?Sized,
T: InitializableFromZeroed + ?Sized,
fn clear(&mut self)
impl<T> From<T> for T
[src]
impl<T> InitializableFromZeroed for T where
T: Default,
T: Default,
unsafe fn initialize(place: *mut T)
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.
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.
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>,