-1

I need a little help i have register a Application in Azure Active Directory now I want to log in a user with resource and client credentials i do not want to add client Id how can i log in the user?
I am using the following code having Exception

Object reference not set to an instance of an object.

How can I solve it any suggestions?

private AuthenticationContext authContext;
public  void button1_Click(object sender, EventArgs e)
{
    try
    {
        string userName = "USERNAME";
        string password = "PASSWORD";

        string url = "https://.com/authentication";
        ClientCredential obj = new ClientCredential(userName, password);

        AuthenticationResult result = null;
        result = authContext.AcquireToken(url, obj);
    }
    catch (Exception ex)
    { }
} 
VMAtm
  • 27,943
  • 17
  • 79
  • 125
  • 2
    On which line you get this exception? Did you debug your code? Related: [What is a `NullReferenceException` and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Soner Gönül Apr 06 '15 at 14:46
  • @soner i am getting the exception on this line of code "result = authContext.AcquireToken(url, obj);" – Bilal Pervaiz Apr 06 '15 at 14:51
  • Have you debugged through your code? I doubt `authContext` is initialized at that line unless you are initializing it somewhere else? – sǝɯɐſ Apr 06 '15 at 15:29
  • you haven't instantiated your authContext object ,, – Coder1409 Apr 06 '15 at 15:29
  • does i have to initialized my authContext null............? – Bilal Pervaiz Apr 07 '15 at 06:15
  • @SonerGönül i have solved the exception now i have an other exception like"AADSTS70001: Application with identifier ABC was not found in the directory "abc" Trace ID: "abc" Correlation ID: "abc" Timestamp: 2015-04-09 10:05:55Z" can u guide me what kind of exception is this and how can i solve it.....? – Bilal Pervaiz Apr 09 '15 at 10:15

1 Answers1

0

In your code you are using the AuthenticationContext authContext variable, but I can't see if you are initializing it.

I think you should check it first

VMAtm
  • 27,943
  • 17
  • 79
  • 125