簡體   English   中英

如何從身份驗證提示彈出窗口中獲取用戶名

[英]How to get username from authentication prompt popup

我有 SharePoint 在線經典頁面,其中有一些自定義 JavaScript 和 jQuery 腳本已實現,第三方 Z303CB0EF5825825 應用程序需要 BBBE0EF9EDB90892AZD61。 當用戶訪問該頁面時,系統會提示他輸入用戶名和密碼。 如何從此提示中獲取用戶名? 提示是標准的,看起來像這樣(圖片不是我的) 在此處輸入圖像描述

您可以使用 SharePoint 的 javascript API 來檢索當前用戶的信息。

_spPageContextInfo.userId

請參閱: https://social.technet.microsoft.com/wiki/contents/articles/29766.sharepoint-understanding-the-sppagecontextinfo-object.aspx

另一個建議是使用 API:

<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(getCurrentUser, "sp.js");
 
var currentUser;
 
function getCurrentUser(){
var ctx= new SP.ClientContext.get_current();
var web = ctx.get_web();
currentUser = web.get_currentUser();
ctx.load(currentUser);
ctx.executeQueryAsync(onSuccess, onFailure);
}
 
function onSuccess() {
alert(currentUser.get_title()); // Domain\Account 
alert(currentUser.get_email());
document.getElementById('userLogin').innerHTML = currentUser.get_loginName(); 
}
 
function onFailure() {
alert('request failed' + args.get_message() + '\n' + args.get_stackTrace());
}
 
</script>
 
<div>Currently Logged User:
    <span id="userLogin"></span>
</div>

微軟參考: https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code

如果有人仍然對此感興趣,我找到了一種使用 microsoft graph API https://docs.microsoft.com/en-us/graph/api/user-get?view=graph-rest-1.0獲取用戶主體名稱的方法&tabs=http

https://graph.microsoft.com/v1.0/me?$select=mailnickname,onpremisesUserprincipalName是我需要的實際請求

暫無
暫無

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

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