How can i get the access token from identityserver4?
I am using identityserver4 with my asp.net core and angular2 application and its working great.Now my requirement is bit changed now for mobile applications i want to do login by user entres his/her mobile number and we check if that user with given phone number exist then send One time password(OTP).And now i want to generate access token only based on the phone number and one time password.How can i do this in identityserver4? I have tried https://localhost:44363/connect/token link so i can use my logics in this method but i don't know where this url is hitting.Kindly help me out.Thnaks in advance
This seems to be a general question about IdentityServer - not a bug report or an issue.
Please use StackOverflow for that. This has the advantage that questions and answers can be easily found by search engines, and that there are more people answering questions than just us.
For IdentityServer3 https://stackoverflow.com/questions/tagged/?tagnames=identityserver3&sort=newest
For IdentityServer4 https://stackoverflow.com/questions/tagged/?tagnames=identityserver4&sort=newest
For commercial support options - visit https://identityserver.io
You can get the access token from the HTTP Header:
private static string GetAccessToken(HttpContext httpContext)
{
var accessToken = (httpContext.Request.Headers as FrameRequestHeaders).HeaderAuthorization;
var token = accessToken.First().Remove(0, "Bearer ".Length);
return token;
}
@MovGP0 May you please elaborate a bit on where exactly your piece of code can be used?
@behrooz66 usually you don't use this at all, but use a library like IdentityModel instead.
Simplified @MovGP0 answer (IdentityServer4.AccessTokenValidation 2.7.0 + IdentityModel 3.10.0):
services.AddScoped(provider =>
{
//
var httpService = provider.GetService<IHttpContextAccessor>();
var token = httpService.HttpContext.Request.Headers["Authorization"][0].Remove(0, "Bearer ".Length);
var userGuid = Guid.Parse(httpService.HttpContext.User.FindFirst("sub").Value);
// use token
});
None of above answers worked out for me. Need to use IdentityServer Tools from IDs4 (IssueJwtAsync) Found the right idea & solution here:
http://docs.identityserver.io/en/latest/topics/tools.html https://stackoverflow.com/a/54913136 https://github.com/IdentityServer/IdentityServer4/issues/2884
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.