मेरे एक ही आइटम वर्तमान संदर्भ में सभी आइटम fronm खोजने के लिए मैं लगातार यह त्रुटि संदेश प्राप्त करने के लिए लग रहे हैं कोशिश कर रहा हूँ, लेकिन:EWS: "दूरस्थ सर्वर से त्रुटि आई (401) अनधिकृत"
The request failed. The remote server returned an error: (401) Unauthorized.
सबसे पहले, मैं विनिमय सेवा का उपयोग करने के लिए सब कुछ सेट:
var signInUserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
var userObjectId = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
AuthenticationResult authenticationResult = null;
AuthenticationContext authenticationContext = new AuthenticationContext(
SettingsHelper.Authority, new model.ADALTokenCache(signInUserId));
authenticationResult = authenticationContext.AcquireToken(
SettingsHelper.ServerName,
new ClientCredential(SettingsHelper.ClientId, SettingsHelper.ClientSecret));
ExchangeService exchange = new ExchangeService(ExchangeVersion.Exchange2013);
exchange.Url = new Uri(SettingsHelper.ServerName + "ews/exchange.asmx");
exchange.TraceEnabled = true;
exchange.TraceFlags = TraceFlags.All;
exchange.Credentials = new OAuthCredentials(authenticationResult.AccessToken);
और फिर मैं क्या परिभाषित मद मैं (आईडी के आधार पर) प्राप्त करना चाहते हैं:
ItemView view = new ItemView(5);
view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
var tempId = id.Replace('-', '/').Replace('_', '+');
SearchFilter.IsEqualTo searchid = new SearchFilter.IsEqualTo(ItemSchema.Id, tempId);
और अंत में कम से कम, मैं इस आइटम के लिए खोज करने के लिए प्रयास करते हैं, मेरे आइटम के भीतर:
FindItemsResults<Microsoft.Exchange.WebServices.Data.Item> results = exchange.FindItems(WellKnownFolderName.Inbox, searchid, view);
और यह वह जगह है जहाँ मेरी त्रुटि होता है। मैंने ऐसा करने के कई अन्य तरीकों की कोशिश की है, लेकिन इससे कोई फर्क नहीं पड़ता कि मैं क्या करता हूं, मुझे अनधिकृत मिलता है।
क्या कोई इस समस्या को हल करने के लिए सही तरीके से मुझे मार्गदर्शन कर सकता है?
authenticationResult = authenticationContext.AcquireToken(
SettingsHelper.ServerName,
new ClientCredential(SettingsHelper.ClientId, SettingsHelper.ClientSecret));
के रूप में मैं debugging कोड से देख सकते हैं:
संपादित
मैं से पहुँच टोकन प्राप्त करते हैं।
रीफ्रेश टोकन हालांकि मौजूद है, और अगर यह कहने के लिए कुछ नहीं है मैं नहीं जानता? ,
The access token is acquired using an authentication method that is too weak to allow access for this application. Presented auth strength was 1, required is 2
मैं decoded the JWT के रूप में यह मेरी परिणाम है::
संपादित
मैं बस जहां मैं इस देखा में exchange.ResponseHeaders
में मेरी सभी तरह डिबग करने में कामयाब रहे
{
typ: "JWT",
alg: "RS256",
x5t: "MnC_VZcATfM5pOYiJHMba9goEKY",
kid: "MnC_VZcATfM5pOYiJHMba9goEKY"
}.
{
aud: "https://outlook.office365.com/",
iss: "https://sts.windows.net/d35f5b06-f051-458d-92cc-2b8096b4b78b/",
iat: 1445416753,
nbf: 1445416753,
exp: 1445420653,
ver: "1.0",
tid: "d35f5b06-f051-458d-92cc-2b8096b4b78b",
oid: "c5da9088-987d-463f-a730-2706f23f3cc6",
sub: "c5da9088-987d-463f-a730-2706f23f3cc6",
idp: "https://sts.windows.net/d35f5b06-f051-458d-92cc-2b8096b4b78b/",
appid: "70af108f-5c8c-4ee4-a40f-ab0b6f5922e0",
appidacr: "1"
}.
[signature]
यहां से कहाँ जाना है?
मैं कठिन सेट "exchange.Credentials" सुझाव है कि जब तक आप प्रमाणीकरण बाहर काम किया है ... ।जैसा कि ऐसा लगता है कि आपकी समस्या है .. – Seabizkit
एक्सचेंज। प्रमाण-पत्र = नए वेब क्रेडेंशियल (authEmailAddress, authEmailPassword, "DOMAINIFYOUHAVEONE"); – Seabizkit
@ सेबिजकिट यह काम करता है। यही वह है जो मैंने शुरू करने के लिए किया था, जो ठीक काम करता है, लेकिन मैं ओएथ – Detilium