ASP.NET Core 2.0 Bearer Auth without Identity

Did an edit to make it compatible with ASP.NET Core 2.0. Firstly, some Nuget packages: Microsoft.AspNetCore.Authentication.JwtBearer Microsoft.AspNetCore.Identity System.IdentityModel.Tokens.Jwt System.Security.Cryptography.Csp Then some basic data transfer objects. // Presumably you will have an equivalent user account class with a user name. public class User { public string UserName { get; set; } } public class JsonWebToken { … Read more

oauth2 error AADSTS90014: The request body must contain the following parameter: ‘grant_type’

You shouldn’t send grant_type neither in params nor in headers. Those should be sent in body params then only it will work. Url: https://login.microsoftonline.com/common/oauth2/v2.0/token client_id, scope and redirect_uri params can be sent as query params. where as grant_type, code and client_secret should sent in body params. grant_type:authorization_code, code: {code you got from the authorization step}, … Read more

Authorization in ASP.NET Core. Always 401 Unauthorized for [Authorize] attribute

At the request of others here is the answer: The problem was with the middleware order in Startup.cs public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { ConfigureAuth(app); // your authorisation configuration app.UseMvc(); } Why middleware order is important? If we put app.UseMvc() first – then the MVC actions would get in the routing and … Read more

Authorization Bearer token in HttpClient?

I have come across similar situation, I was able to do it by following way, I hope this will help others. import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; public class HttpURLConnectionExample { public static void main(String[] args) throws Exception { // Sending get request URL url = new URL(“http://example-url”); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); … Read more

Authorization bearer token Angular 5

I suggest to use HttpInterceptor for setting default HTTP headers on outgoing requests rather than adding an additional HTTP header to each call. HTTP Client – Setting default headers @ angular.io In your example you can do the following: import { Http, Headers, Response } from ‘@angular/http’; getLoggedInUser(auth_token): Observable<any> { const headers = new Headers({ … Read more

How to properly use Bearer tokens?

1.Improving the security because if token is not sent in the header that sent in url, it will be logged by the network system, the server log …. 2.A good function to get Bearer tokens /** * Get header Authorization * */ function getAuthorizationHeader(){ $headers = null; if (isset($_SERVER[‘Authorization’])) { $headers = trim($_SERVER[“Authorization”]); } else … Read more

Return more info to the client using OAuth Bearer Tokens Generation and Owin in WebApi

You can add as many claims as you want. You can add the standard set of claims from System.Security.Claims or create your own. Claims will be encrypted in your token so they will only be accessed from the resource server. If you want your client to be able to read extended properties of your token … Read more

Web API Authentication Basic vs Bearer

The Basic and Digest authentication schemes are dedicated to the authentication using a username and a secret (see RFC7616 and RFC7617). The Bearer authentication scheme is dedicated to the authentication using a token and is described by the RFC6750. Even if this scheme comes from an OAuth2 specification, you can still use it in any … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)