0
votes

How do you use Azure App Services to authenticate a Web API Route?

What do I need to send to the /api/test/auth route to return a 200!?

The /api/test/noauth route works fine without the [Authorize] attribute.

[Authorize]
    [HttpGet]
    [Route("auth")]
    public IActionResult TestAuth()
    {
        return new ObjectResult("This requires authentication.");
    }

    [HttpGet]
    [Route("noauth")]
    public IActionResult TestNoAuth()
    {
        return new ObjectResult("This doesn't require authentication.");
    }

I've set it up so when you hit the /.auth/login/twitter route, it will redirect to the Twitter login page, which returns to the callback URL with a Bearer token, but my bearer token is not working??

Send with Bearer Token

This returns a 401 Unauthorized error? Do I need to set up something in my code to handle Twitter Authorization?

2

2 Answers

0
votes

In your twitter application,first click on Settings and change the Application Type to "Read, Write and Access direct messages".Then once your Twitter application has been updated to "Read, Write and Access direct messages", click on the Home tab, and "create your access token". If you have already created the token, regenerate it. Also Regenerate Consumer Key and Consumer Secret.

0
votes

Microsoft released adal.js to handle the grunt work of handling the tokens from authentication services. I'm struggling with the same problem using AzureActiveDirectory authentication for an App Service web api. There is a sample leveraging it with Angular, but it will need to be modified for use in an ajax call. https://github.com/AzureAD/azure-activedirectory-library-for-js