ASP.NET Core 3.1 - JWT Authentication API
For documentation and instructions check out https://jasonwatmore.com/post/2019/10/11/aspnet-core-3-jwt-authentication-tutorial-with-example-api
ASP.NET Core 3.1 JWT Authentication API
Home Page: https://jasonwatmore.com/post/2019/10/11/aspnet-core-3-jwt-authentication-tutorial-with-example-api
License: MIT License
ASP.NET Core 3.1 - JWT Authentication API
For documentation and instructions check out https://jasonwatmore.com/post/2019/10/11/aspnet-core-3-jwt-authentication-tutorial-with-example-api
When I run the command dotnet run
. It shows the following error. Please guide.
C:\Users\khan\Downloads\Compressed\aspnet-core-3-jwt-authentication-api-master\WebApi.csproj : error NU1100: Unable to resolve 'Microsoft.AspNetCore.Authentication.JwtBearer (>= 3.1.6)' for '.NETCoreApp,Version=v3.1'.
C:\Users\khan\Downloads\Compressed\aspnet-core-3-jwt-authentication-api-master\WebApi.csproj : error NU1100: Unable to resolve 'System.IdentityModel.Tokens.Jwt (>= 6.7.1)' for '.NETCoreApp,Version=v3.1'.
The build failed. Fix the build errors and run again.
My dotnet version is:
dotnet --version
3.1.408
When I try to revoke the token the request will fail in line 5:
1. private (RefreshToken, Account) getRefreshToken(string token)
2. {
3. var account = _context.Accounts.SingleOrDefault(u => u.RefreshTokens.Any(t => t.Token == token));
4. if (account == null) throw new AppException("Invalid token");
5. var refreshToken = account.RefreshTokens.Single(x => x.Token == token);
6. if (!refreshToken.IsActive) throw new AppException("Invalid token");
7. return (refreshToken, account);
8. }
It passes line 3 and 4, so it means it could find the RefreshToken and the related account in line 3, however, later in line 5 I have encountered with the following error:
"message": "Sequence contains no matching element"
I am following your blog to try out your full stack application. I have tried all different front end applications, but when I try to login or sign up, I always get this error
SyntaxError: Unexpected token < in JSON at position 0
Using Devtools in the browser, I can see that we are always failing in this line in the main.js:
/var r=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable;function a(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}e.exports=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;n<10;n++)t[""+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(t).map((function(e){return t[e]})).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach((function(e){r[e]=e})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(e){return!1}}()?Object.assign:function(e,t){for(var n,l,u=a(e),c=1;c<arguments.length;c++){for(var s in n=Object(arguments[c]))o.call(n,s)&&(u[s]=n[s]);if(r){l=r(n);for(var f=0;f<l.length;f++)i.call(n,l[f])&&(u[l[f]]=n[l[f]])}}return u}},function(e,t,n){"use strict";function r(e){var t,n=e.Symbol;return"function"==typeof n?n.observable?t=n.observable:(t=n("observable"),n.observable=t):t="@@observable",t}n.d(t,"a",(function(){return r}))},function(e,t,n){(function(e){!function(t){"use strict";function n(e,t){e.super=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}function r(e,t){Object.defineProperty(this,"kind",{value:e,enumerable:!0}),t&&t.length&&Object.defineProperty(this,"path",{value:t,enumerable:!0})}function o(e,t,n){o.super_.call(this,"E",e),Object.defineProperty(this,"lhs",{value:t,enumerable:!0}),Object.defineProperty(this,"rhs",{value:n,enumerable:!0})}function i(e,t){i.super_.call(this,"N",e),Object.defineProperty(this,"rhs",{value:t,enumerable:!0})}function a(e,t){a.super_.call(this,"D",e),Object.defineProperty(this,"lhs",{value:t,enumerable:!0})}function l(e,t,n){l.super_.call(this,"A",e),Object.defineProperty(this,"index",{value:t,enumerable:!0}),Object.defineProperty(this,"item",{value:n,enumerable:!0})}function u(e,t,n){var r=e.slice((n||t)+1||e.length);return e.length=t<0?e.length+t:t,e.push.apply(e,r),e}function c(e){var t=void 0===e?"undefined":k(e);return"object"!==t?t:e===Math?"math":null===e?"null":Array.isArray(e)?"array":"[object Date]"===Object.prototype.toString.call(e)?"date":"function"==typeof e.toString&&/^/.//.test(e.toString())?"regexp":"object"}function s(e,t,n,r,f,d,p){p=p||[];var h=(f=f||[]).slice(0);if(void 0!==d){if(r){if("function"==typeof r&&r(h,d))return;if("object"===(void 0===r?"undefined":k(r))){if(r.prefilter&&r.prefilter(h,d))return;if(r.normalize){var m=r.normalize(h,d,e,t);m&&(e=m[0],t=m[1])}}}h.push(d)}"regexp"===c(e)&&"regexp"===c(t)&&(e=e.toString(),t=t.toString());var v=void 0===e?"undefined":k(e),y=void 0===t?"undefined":k(t),g="undefined"!==v||p&&p[p.length-1].lhs&&p[p.length-1].lhs.hasOwnProperty(d),b="undefined"!==y||p&&p[p.length-1].rhs&&p[p.length-1].rhs.hasOwnProperty(d);if(!g&&b)n(new i(h,t));else if(!b&&g)n(new a(h,e));else if(c(e)!==c(t))n(new o(h,e,t));else if("date"===c(e)&&e-t!=0)n(new o(h,e,t));else if("object"===v&&null!==e&&null!==t)if(p.filter((function(t){return t.lhs===e})).length)e!==t&&n(new o(h,e,t));else{if(p.push({lhs:e,rhs:t}),Array.isArray(e)){var w;for(e.length,w=0;w<e.length;w++)w>=t.length?n(new l(h,w,new a(void 0,e[w]))):s(e[w],t[w],n,r,h,w,p);for(;w<t.length;)n(new l(h,w,new i(void 0,t[w++])))}else{var E=Object.keys(e),x=Object.keys(t);E.forEach((function(o,i){var a=x.indexOf(o);a>=0?(s(e[o],t[o],n,r,h,o,p),x=u(x,a)):s(e[o],void 0,n,r,h,o,p)})),x.forEach((function(e){s(void 0,t[e],n,r,h,e,p)}))}p.length=p.length-1}else e!==t&&("number"===v&&isNaN(e)&&isNaN(t)||n(new o(h,e,t)))}function f(e,t,n,r){return r=r||[],s(e,t,(function(e){e&&r.push(e)}),n),r.length?r:void 0}function d(e,t,n){if(e&&t&&n&&n.kind){for(var r=e,o=-1,i=n.path?n.path.length-1:0;++o<i;)void 0===r[n.path[o]]&&(r[n.path[o]]="number"==typeof n.path[o]?[]:{}),r=r[n.path[o]];switch(n.kind){case"A":!function e(t,n,r){if(r.path&&r.path.length){var o,i=t[n],a=r.path.length-1;for(o=0;o<a;o++)i=i[r.path[o]];switch(r.kind){case"A":e(i[r.path[o]],r.index,r.item);break;case"D":delete i[r.path[o]];break;case"E":case"N":i[r.path[o]]=r.rhs}}else switch(r.kind){case"A":e(t[n],r.index,r.item);break;case"D":t=u(t,n);break;case"E":case"N":t[n]=r.rhs}return t}(n.path?r[n.path[o]]:r,n.index,n.item);break;case"D":delete r[n.path[o]];break;case"E":case"N":r[n.path[o]]=n.rhs}}}function p(e){return"color: "+A[e].color+"; font-weight: bold"}function h(e,t,n,r){var o=f(e,t);try{r?n.groupCollapsed("diff"):n.group("diff")}catch(e){n.log("diff")}o?o.forEach((function(e){var t=e.kind,r=function(e){var t=e.kind,n=e.path,r=e.lhs,o=e.rhs,i=e.index,a=e.item;switch(t){case"E":return[n.join("."),r,"→",o];case"N":return[n.join("."),o];case"D":return[n.join(".")];case"A":return[n.join(".")+"["+i+"]",a];default:return[]}}(e);n.log.apply(n,["%c "+A[t].text,p(t)].concat(S(r)))})):n.log("—— no diff ——");try{n.groupEnd()}catch(e){n.log("—— diff end —— ")}}function m(e,t,n,r){switch(void 0===e?"undefined":k(e)){case"object":return"function"==typeof e[r]?e[r].apply(e,S(n)):e[r];case"function":return e(t);default:return e}}function v(e,t){var n=t.logger,r=t.actionTransformer,o=t.titleFormatter,i=void 0===o?function(e){var t=e.timestamp,n=e.duration;return function(e,r,o){var i=["action"];return i.push("%c"+String(e.type)),t&&i.push("%c@ "+r),n&&i.push("%c(in "+o.toFixed(2)+" ms)"),i.join(" ")}}(t):o,a=t.collapsed,l=t.colors,u=t.level,c=t.diff,s=void 0===t.titleFormatter;e.forEach((function(o,f){var d=o.started,p=o.startedTime,v=o.action,y=o.prevState,g=o.error,b=o.took,w=o.nextState,x=e[f+1];x&&(w=x.prevState,b=x.started-d);var k=r(v),S="function"==typeof a?a((function(){return w}),v,o):a,T=E(p),A=l.title?"color: "+l.title(k)+";":"",C=["color: gray; font-weight: lighter;"];C.push(A),t.timestamp&&C.push("color: gray; font-weight: lighter;"),t.duration&&C.push("color: gray; font-weight: lighter;");var P=i(k,T,b);try{S?l.title&&s?n.groupCollapsed.apply(n,["%c "+P].concat(C)):n.groupCollapsed(P):l.title&&s?n.group.apply(n,["%c "+P].concat(C)):n.group(P)}catch(e){n.log(P)}var O=m(u,k,[y],"prevState"),=m(u,k,[k],"action"),N=m(u,k,[g,y],"error"),R=m(u,k,[w],"nextState");if(O)if(l.prevState){var j="color: "+l.prevState(y)+"; font-weight: bold";n[O]("%c prev state",j,y)}else n[O]("prev state",y);if()if(l.action){var I="color: "+l.action(k)+"; font-weight: bold";n[]("%c action ",I,k)}else n[]("action ",k);if(g&&N)if(l.error){var M="color: "+l.error(g,y)+"; font-weight: bold;";n[N]("%c error ",M,g)}else n[N]("error ",g);if(R)if(l.nextState){var D="color: "+l.nextState(w)+"; font-weight: bold";n[R]("%c next state",D,w)}else n[R]("next state",w);c&&h(y,w,n,S);try{n.groupEnd()}catch(e){n.log("—— log end ——")}}))}function y(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=Object.assign({},C,e),n=t.logger,r=t.stateTransformer,o=t.errorTransformer,i=t.predicate,a=t.logErrors,l=t.diffPredicate;if(void 0===n)return function(){return function(e){return function(t){return e(t)}}};if(e.getState&&e.dispatch)return console.error("[redux-logger] redux-logger not installed. Make sure to pass logger instance as middleware:\n// Logger with default options\nimport { logger } from 'redux-logger'\nconst store = createStore(\n reducer,\n applyMiddleware(logger)\n)\n// Or you can create your own logger with custom options http://bit.ly/redux-logger-options\nimport createLogger from 'redux-logger'\nconst logger = createLogger({\n // ...options\n});\nconst store = createStore(\n reducer,\n applyMiddleware(logger)\n)\n"),function(){return function(e){return function(t){return e(t)}}};var u=[];return function(e){var n=e.getState;return function(e){return function(c){if("function"==typeof i&&!i(n,c))return e(c);var s={};u.push(s),s.started=x.now(),s.startedTime=new Date,s.prevState=r(n()),s.action=c;var f=void 0;if(a)try{f=e(c)}catch(e){s.error=o(e)}else f=e(c);s.took=x.now()-s.started,s.nextState=r(n());var d=t.diff&&"function"==typeof l?l(n,c):t.diff;if(v(u,Object.assign({},t,{diff:d})),u.length=0,s.error)throw s.error;return f}}}}var g,b,w=function(e,t){return function(e,t){return new Array(t+1).join(e)}("0",t-e.toString().length)+e},E=function(e){return w(e.getHours(),2)+":"+w(e.getMinutes(),2)+":"+w(e.getSeconds(),2)+"."+w(e.getMilliseconds(),3)},x="undefined"!=typeof performance&&null!==performance&&"function"==typeof performance.now?performance:Date,k="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},S=function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)},T=[];g="object"===(void 0===e?"undefined":k(e))&&e?e:"undefined"!=typeof window?window:{},(b=g.DeepDiff)&&T.push((function(){void 0!==b&&g.DeepDiff===f&&(g.DeepDiff=b,b=void 0)})),n(o,r),n(i,r),n(a,r),n(l,r),Object.defineProperties(f,{diff:{value:f,enumerable:!0},observableDiff:{value:s,enumerable:!0},applyDiff:{value:function(e,t,n){e&&t&&s(e,t,(function(r){n&&!n(e,t,r)||d(e,t,r)}))},enumerable:!0},applyChange:{value:d,enumerable:!0},revertChange:{value:function(e,t,n){if(e&&t&&n&&n.kind){var r,o,i=e;for(o=n.path.length-1,r=0;r<o;r++)void 0===i[n.path[r]]&&(i[n.path[r]]={}),i=i[n.path[r]];switch(n.kind){case"A":!function e(t,n,r){if(r.path&&r.path.length){var o,i=t[n],a=r.path.length-1;for(o=0;o<a;o++)i=i[r.path[o]];switch(r.kind){case"A":e(i[r.path[o]],r.index,r.item);break;case"D":case"E":i[r.path[o]]=r.lhs;break;case"N":delete i[r.path[o]]}}else switch(r.kind){case"A":e(t[n],r.index,r.item);break;case"D":case"E":t[n]=r.lhs;break;case"N":t=u(t,n)}return t}(i[n.path[r]],n.index,n.item);break;case"D":case"E":i[n.path[r]]=n.lhs;break;case"N":delete i[n.path[r]]}}},enumerable:!0},isConflict:{value:function(){return void 0!==b},enumerable:!0},noConflict:{value:function(){return T&&(T.forEach((function(e){e()})),T=null),f},enumerable:!0}});var A={E:{color:"#2196F3",text:"CHANGED:"},N:{color:"#4CAF50",text:"ADDED:"},D:{color:"#F44336",text:"DELETED:"},A:{color:"#2196F3",text:"ARRAY:"}},C={level:"log",logger:console,logErrors:!0,collapsed:void 0,predicate:void 0,duration:!1,timestamp:!0,stateTransformer:function(e){return e},actionTransformer:function(e){return e},errorTransformer:function(e){return e},colors:{title:function(){return"inherit"},prevState:function(){return"#9E9E9E"},action:function(){return"#03A9F4"},nextState:function(){return"#4CAF50"},error:function(){return"#F20404"}},diff:!1,diffPredicate:void 0,transformer:void 0},P=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.dispatch,n=e.getState;return"function"==typeof t||"function"==typeof n?y()({dispatch:t,getState:n}):void console.error("\n[redux-logger v3] BREAKING CHANGE\n[redux-logger v3] Since 3.0.0 redux-logger exports by default logger with default settings.\n[redux-logger v3] Change\n[redux-logger v3] import createLogger from 'redux-logger'\n[redux-logger v3] to\n[redux-logger v3] import { createLogger } from 'redux-logger'\n")};t.defaults=C,t.createLogger=y,t.logger=P,t.default=P,Object.defineProperty(t,"__esModule",{value:!0})}(t)}).call(this,n(8))},function(e,t,n){"use strict";
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.