Get user's phone number in Firefox OS

2019-02-24 19:58发布

问题:

Is there any way to fetch user’s phone number in Firefox OS?

If so, any help would be appreciated.

回答1:

According to Mozilla's app permissions page, there is an permission called "phonenumberservice" but there is no information about it. Anyway, the permision is listed under the "Internal (Certified) app permissions", which means that, when available, it can only be used by "system-level apps and default apps created by Mozilla/operators/OEMs".



回答2:

With Firefox 2.0 you should be able to use Mobile Identity API: https://wiki.mozilla.org/WebAPI/MobileIdentity https://bugzilla.mozilla.org/show_bug.cgi?id=1021594 I believe the permission is:

"permissions": { "mobileid": {} }

And it is privileged.



回答3:

So, as @Jason said, the Mobile Identity API provides this capability, and not just for certified, but for privileged applications. So it is no longer just for OEMs.

The Mozilla Wiki site shows the API:

dictionary MobileIdOptions {
    boolean forceSelection = false;
};
partial interface Navigator {
    Promise getMobileIdAssertion(optional MobileIdOptions options);
};

The site also provides a sample code skeleton for this:

function verifyAssertion(aAssertion) {
    // Make use of the remote verification API
    // and return the verified msisdn.
    // NB: This is necessary to make sure that the user *really* controls this phone number!
}

// Request a mobile identity assertion and force the chrome UI to
// allow the user to change a possible previous selection.
navigator.getMobileIdAssertion({ forceSelection: true })
.then(
    (assertion) => {
        verifyAssertion(assertion)
        .then(
            (msisdn) => {
                // Do stuff with the msisdn.
            }
        );
    },
    (error) {
        // Process error.
    };
);

For this to work, you need to add the mobileid permission in the manifest file, for example like this (I made up the description):

"permissions": {
    "mobileid": {
        "description": "Required for sending SMS for two factor authentication",
        "access": "readonly"
    }
}

PS: I made this answer, because most answers are outdated, and the one that isn't, does not contain all useful information.

References:

  • App Manifest Documentation
  • Firefox Remote Verification