c# - Sharing OAuth Tokens Across Two Web API projects -
i have created web api application oauth token authentication. worked without issue when token server running on same application service. however, i'd move authorization service own application (vs project) , use across several web api projects working on. however, when isolated authorization logic it's own project original service no longer treats tokens generated valid. question is, possible 1 web api project generate token 1 validate? here owin startup code both auth service , original service
auth service:
public void configuration(iappbuilder app) { // more information on how configure application, visit http://go.microsoft.com/fwlink/?linkid=316888 httpconfiguration config = new httpconfiguration(); configureoauth(app); webapiconfig.register(config); app.usewebapi(config); app.usecors(microsoft.owin.cors.corsoptions.allowall); } private void configureoauth(iappbuilder app) { oauthauthorizationserveroptions oauthserveroptions = new oauthauthorizationserveroptions() { allowinsecurehttp = true, tokenendpointpath = new pathstring("/token"), accesstokenexpiretimespan = timespan.fromdays(1), provider = new simpleauthorizationserverprovider() }; // token generation app.useoauthauthorizationserver(oauthserveroptions); app.useoauthbearerauthentication(new oauthbearerauthenticationoptions()); } original service:
public void configuration(iappbuilder app) { configureoauth(app); // more information on how configure application, visit http://go.microsoft.com/fwlink/?linkid=316888 httpconfiguration config = new httpconfiguration(); config.suppressdefaulthostauthentication(); config.filters.add(new hostauthenticationfilter(oauthdefaults.authenticationtype)); webapiconfig.register(config); app.usecors(microsoft.owin.cors.corsoptions.allowall); app.usewebapi(config); } public void configureoauth(iappbuilder app) { var oauthbeareroptions = new oauthbearerauthenticationoptions(); app.useoauthbearerauthentication(oauthbeareroptions); }
just stumbled across q whilst researching myself. tl;dr answer tokens generated using machinekey properties in machine.config file: if want host on multiple servers need override this.
the machinekey can overridden in web.config :
<system.web> <machinekey validationkey="value goes here" decryptionkey="value goes here" validation="sha1" decryption="aes"/> </system.web> machine keys should generated locally - using online service not secure. kb article generating keys
orginal ref here http://bitoftech.net/2014/09/24/decouple-owin-authorization-server-resource-server-oauth-2-0-web-api
Comments
Post a Comment