asp.net web api - ODataController BearerToken Authorization denied -



asp.net web api - ODataController BearerToken Authorization denied -

i'm trying implement authentication provider webapi services. im using guide: http://bitoftech.net/2014/06/01/token-based-authentication-asp-net-web-api-2-owin-asp-net-identity/ testing purpose i've implemented 2 controllers in separate webapi-project:

public class testapicontroller : apicontroller { [authorize] public string get() { homecoming "secure"; } public string get(int id) { homecoming "not secure"; } } public class testodatacontroller : odatacontroller { [authorize] [enablequery] public httpresponsemessage get() { homecoming new httpresponsemessage(httpstatuscode.ok); } }

my goal utilize odata controller in end.

when phone call localhost:port/api/testapi , set bearer token in header, everythings works fine. when phone call localhost:port/odata/testodata , add together token receive message :

authorization has been denied request.

it doesn't matter if set token in header or not. if remove authorize attribute works fine. i'm using postman phone call methods, if of interest. @ moment i'm using iis-express visual studio host controllers, iis alread configured produces same message.

my startup.cs (the interesting part...)

public void configuration(iappbuilder app) { var config = new httpconfiguration(); configureoauth(app); filterconfig.register(config); odataconfig.register(config); webapiconfig.register(config); app.usecors(corsoptions.allowall); app.usewebapi(config); } public void configureoauth(iappbuilder app) { //token consumption app.useoauthbearerauthentication(new oauthbearerauthenticationoptions {}); }

odata , webconfig :

public class odataconfig { public static void register(httpconfiguration config) { odataconventionmodelbuilder modelbuilder = new odataconventionmodelbuilder(); modelbuilder.entityset<mymodel>("mymodel"); var conventions = odataroutingconventions.createdefault(); var route = config.routes.mapodataroutefixed( routename: "odataroute", routeprefix: "odata", model: modelbuilder.getedmmodel(), conventions: conventions) route; } } public static class webapiconfig { public static void register(httpconfiguration config) { config.maphttpattributeroutes(); config.routes.maphttproute( name: "defaultapi", routetemplate: "api/{controller}/{id}", defaults: new { id = routeparameter.optional } ); config.formatters.jsonformatter.serializersettings.contractresolver = new camelcasepropertynamescontractresolver(); } }

the account-controller add together new user in project. database looks , token generation works, too. it's same code illustration bitoftech-demo.

i don't see difference betweens these controllers. auhtorize attribute recognized controller...but else wrong. hints appreciated.

update after research , first answers updated startup values. old options necessary token generation , not token consumption. still api controllers works , odatacontroller throws "authorization denied".

update2 worked now. i'm not quite sure why. removed filterconfig :

public class filterconfig { public static void register(httpconfiguration config) { //config.suppressdefaulthostauthentication(); //config.filters.add(new hostauthenticationfilter(oauthdefaults.authenticationtype)); } }

but have no thought why working before api controller , not odata controller...

if utilize 1 project getting token , webapi, both must have same machine key in web.config.

in next post of same serial next explains how it: decouple owin authorization server resource server

example:

<system.web> ... <machinekey validationkey="57b449bba8f9e656087ff7848727e122c5f5966f65ac0fc25fb3532193b59cfcd13b370883ffc184c1f1500638f33e6f67b37caed1d9bc65bbc6cffb232bfd0b" decryptionkey="6d9fbe88d16b3fa5b5e6b37460bbe50da85d5b4c482159006b5a337c58aa9e79" validation="sha1" decryption="aes" /> ... </system.web>

asp.net-web-api odata owin

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -