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