1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//! # User Profile info
//!
//! These methods can be used to find out information about the connected user.
use crate::{ApiResult, Error, FirefoxAccount};
use error_support::handle_error;
impl FirefoxAccount {
/// Get profile information for the signed-in user, if any.
///
/// **💾 This method alters the persisted account state.**
///
/// This method fetches a [`Profile`] struct with information about the currently-signed-in
/// user, either by using locally-cached profile information or by fetching fresh data from
/// the server.
///
/// # Arguments
///
/// - `ignore_cache` - if true, always hit the server for fresh profile information.
///
/// # Notes
///
/// - Profile information is only available to applications that have been
/// granted the `profile` scope.
/// - There is currently no API for fetching cached profile information without
/// potentially hitting the server.
/// - If there is no signed-in user, this method will throw an
/// [`Authentication`](FxaError::Authentication) error.
#[handle_error(Error)]
pub fn get_profile(&self, ignore_cache: bool) -> ApiResult<Profile> {
Ok(self.internal.lock().get_profile(ignore_cache)?.into())
}
}
/// Information about the user that controls a Firefox Account.
///
/// This struct represents details about the user themselves, and would typically be
/// used to customize account-related UI in the browser so that it is personalize
/// for the current user.
pub struct Profile {
/// The user's account uid
///
/// This is an opaque immutable unique identifier for their account.
pub uid: String,
/// The user's current primary email address.
///
/// Note that unlike the `uid` field, the email address may change over time.
pub email: String,
/// The user's preferred textual display name.
pub display_name: Option<String>,
/// The URL of a profile picture representing the user.
///
/// All accounts have a corresponding profile picture. If the user has not
/// provided one then a default image is used.
pub avatar: String,
/// Whether the `avatar` URL represents the default avatar image.
pub is_default_avatar: bool,
}