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