Get user's phone number in Firefox OS

随声附和 提交于 2019-12-01 20:34:09

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".

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.

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:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!