none
Pass credentials or token from mail app to webserver to use with EWS Managed API ExchangeService class RRS feed

  • Question

  • I would like to use the Microsoft.Exchange.WebServices.Data.ExchangeService object on the webserver that hosts my mail app.

    Can I authorize using some kind of token or something else passed from the client mail app to ExchangeService  object on the webserver without the need to ask a user interaction to enter credentials?

    Kind regards,


    • Edited by voilbak Tuesday, August 6, 2013 11:41 AM
    Tuesday, August 6, 2013 11:40 AM

All replies

  • anybody?
    Tuesday, September 3, 2013 7:54 AM
  • Hi,

    You can use Mailbox.getCallbackTokenAsync . You can use this token to authenticate against Exchange.

    Have a look at the article below. Please note, above call is only valid from OWA for now.

    http://msdn.microsoft.com/en-us/library/jj984589.aspx

    For sample, look in to the code Modal of GetAttachement sample:

    http://code.msdn.microsoft.com/office/Mail-apps-for-Office-Get-38babdc9

    [If this helps, please mark it as answer.]

    Regards,
    Pallav

    Saturday, September 14, 2013 10:16 AM
  • I get the token in OWA.

    I pass it to the webserver where I run this code

    var service = new ExchangeService(ExchangeVersion.Exchange2013)
                                  {
                                      Credentials = new OAuthCredentials(token),
                                      Url =
                                          new Uri(
                                          "https://outlook.office365.com/EWS/Exchange.asmx")
                                  };
    
                var message = new EmailMessage(service);
                message.Subject = "MySubject";
                message.Body = new MessageBody("MyBody");
                message.ToRecipients.Add("johndoe@company.com");
                message.SendAndSaveCopy();

    I get this exception : 

    ((Microsoft.Exchange.WebServices.Data.ServiceResponseException)(e)).Message "The requested web method is unavailable to this caller or application."

    Why?

    Monday, September 16, 2013 9:33 AM
  • Hi,

    Try using the value provided by EWSUrl property of Mailbox to make EWS request rather than hardcoding the EWS url.

    http://msdn.microsoft.com/en-us/library/jj984594.aspx


    • Edited by Pallav Sharma Monday, September 16, 2013 3:33 PM little addition to text
    Monday, September 16, 2013 3:32 PM
  • I did,

    the url mentioned above was the url i got from the EWSUrl property.

    So the problem remains "The requested web method is unavailable to this caller or application."
    • Edited by voilbak Monday, September 16, 2013 3:41 PM
    Monday, September 16, 2013 3:41 PM
  • Hi Voilbak,

    I am doing a quick test on this and will get back to you. Meanwhile i would suggest you to enable the EWS tracing in the code and share the Request and Response SOAP.


    Thursday, September 19, 2013 5:18 AM
  • Request :

    <Trace Tag="EwsRequest" Tid="6" Time="2013-09-19 13:39:48Z" Version="15.00.0516.014">
      <?xml version="1.0" encoding="utf-8"?>
      <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
        <soap:Header>
          <t:RequestServerVersion Version="Exchange2013" />
        </soap:Header>
        <soap:Body>
          <m:CreateItem MessageDisposition="SendAndSaveCopy">
            <m:SavedItemFolderId>
              <t:DistinguishedFolderId Id="sentitems" />
            </m:SavedItemFolderId>
            <m:Items>
              <t:Message>
                <t:Subject>MySubject</t:Subject>
                <t:Body BodyType="HTML">MyBody</t:Body>
                <t:ToRecipients>
                  <t:Mailbox>
                    <t:EmailAddress>johndoe@company.com</t:EmailAddress>
                  </t:Mailbox>
                </t:ToRecipients>
              </t:Message>
            </m:Items>
          </m:CreateItem>
        </soap:Body>
      </soap:Envelope>
    </Trace>
    

    Response :

    <Trace Tag="EwsResponse" Tid="6" Time="2013-09-19 13:39:59Z" Version="15.00.0516.014">
      <?xml version="1.0" encoding="utf-8"?>
      <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
        <s:Body>
          <s:Fault>
            <faultcode xmlns:a="http://schemas.microsoft.com/exchange/services/2006/types">a:ErrorAccessDenied</faultcode>
            <faultstring xml:lang="en-US">The requested web method is unavailable to this caller or application.</faultstring>
            <detail>
              <e:ResponseCode xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">ErrorAccessDenied</e:ResponseCode>
              <e:Message xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">The requested web method is unavailable to this caller or application.</e:Message>
            </detail>
          </s:Fault>
        </s:Body>
      </s:Envelope>
    </Trace>
    

    I can also send you my test project if you want.

    Thursday, September 19, 2013 1:43 PM
  • Hi,

    Have a look at the Forum post below, which provides details on using OAuth with Exchange 2013.

    http://social.msdn.microsoft.com/Forums/exchange/en-US/1f5e09f3-2284-40d5-865b-69464e069d0e/e2013exchangeonline-ewsma-c-win7win-server-20072010-oauth-authentication-for-exchange

    Tuesday, September 24, 2013 5:26 AM
  • Hi,

    I have read the thread above carefully.

    This explains how to get a token using my mail app id and GetClientAccesToken.

    I don't think this contains a solution for my problem because as Glen Scales states : 

    "Why are trying to use GetClientAccessToken ?? this is used to generate a Token that you can use with in either Exchange, SharePoint or Link based on the credentials your using, hence you would always need credentials to call it.

    If you have Token from SharePoint already you don't need to call this just use the Token you already have via the OAuthCredentials Class."

    Tuesday, September 24, 2013 7:54 AM
  • The token you got is just for authentication not authorization. Currently, mail app support client side JavaScript call EWS Webservices. Please see refered page for detail:

    http://msdn.microsoft.com/en-us/library/office/fp160952.aspx

    Wednesday, February 19, 2014 5:42 AM