簡體   English   中英

ibm-移動優先如何從安全上下文中獲取移動號碼?

[英]How does ibm - mobile first get mobile number from security context?

我正在遵循示例代碼中的“ isRegistered” api。 我不明白我們如何從安全上下文中獲取電話號碼。

我要使用的API是:

@Path("/isRegistered")
@GET
@Produces("application/json")
@OAuthSecurity(enabled = true)
@ApiOperation(value = "Check if a phone number is registered",
        notes = "Check if a phone number is registered",
        httpMethod = "GET",
        response = Boolean.class
)
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "OK",
                response = String.class),
        @ApiResponse(code = 401, message = "Not Authorized",
                response = String.class),
        @ApiResponse(code = 500, message = "Cannot check if phone number is registered",
                response = String.class)
})

public Boolean isRegistered() {
    //Getting client data from the security context
    ClientData clientData = securityContext.getClientRegistrationData();
    if (clientData == null) {
        throw new InternalServerErrorException("This check allowed only from a mobile device.");
    }

    String number = clientData.getProtectedAttributes().get(SMSOTPSecurityCheck.PHONE_NUMBER);
    return number != null && !number.trim().equals("");
}

安全上下文如何具有客戶電話號碼?

此樣本中也有一個客戶項目。 請參考完整的樣本。

此處的客戶端邏輯中,要求用戶提供電話號碼,該電話號碼將通過適配器調用發送到服務器:

MainViewController.codeDialog("Phone Number", message: "Please provide your phone number",isCode: true) { (phone, ok) -> Void in
 if ok {
         let resourseRequest = WLResourceRequest(URL: NSURL(string:"/adapters/smsOtp/phone/register/\(phone)")!, method:"POST")
.....

現在,在適配器代碼路徑@Path(“ / register / {phoneNumber}”)中,注意以下代碼:

clientData.getProtectedAttributes().put(SMSOTPSecurityCheck.PHONE_NUMBER, phoneNumber);
    securityContext.storeClientRegistrationData(clientData);

這是電話號碼與安全性相關的方式。

運行該示例,並使用諸如Wireshark之​​類的工具來分析客戶端和服務器之間的數據流。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM