c# - Get CryptographicException when trying Authorize -
i tried testing web api using microsoft.owin.testing
. problem appears when endpoint has attribute "authorize".
for endpoint without attribute it's okay. when try send request authorize endpoint, in stack trace error:
exception thrown: 'system.security.cryptography.cryptographicexception' in system.security.dll
and response has code 401 - unauthorized
.
but if start in debug, , testing endpoints in browser (or way) it's okay.
my startup class tests
public async void configuration(iappbuilder app) { var config = new httpconfiguration(); config.includeerrordetailpolicy = includeerrordetailpolicy.always; config.services.replace(typeof(iassembliesresolver), new resolvercontroller()); diconfig.register(config, app); oauthconfig.register(app, (oauthsettings)config.dependencyresolver.getservice(typeof(oauthsettings)), (oauthbearerauthenticationoptions)config.dependencyresolver.getservice(typeof(oauthbearerauthenticationoptions))); webapiconfig.register(config, app); }
and here query endpoint
using (var server = testserver.create<startuptest>()) { using (var client = new httpclient(server.handler)) { responce = await server .createrequest("api/me/token/refresh") .addheader("content-type", "application/json") .addheader("authorization", $"bearer {accesstoken}") .postasync(); } }
here endpoint
[httppost] [route("me/token/refresh")] [authorize] [responsetype(typeof(refreshtokenmodelview))] public ihttpactionresult getrefreshtoken() { var userid = user.identity.getuserid<int>(); if (userid <= 0) { return notfound(); } var refreshtoken = _oauthrefreshtokenprovider.createrefreshtoken(userid); return ok(_mapper.map<refreshtokenmodelview>(refreshtoken)); }
can advise something, ideas?
some screens
unauthorized
cryptographic exception
Comments
Post a Comment