Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Access Token URL = https://unsitio/web/token
- Grant Type = password
- Authorization Grants = password
- Client Id = nnnnnnnn
- Client Secret = [Vacio]
- Scope = [Vacio]
- Username = hhhhhh@vvvv.ggg.oooo.lll
- Password = sssssssss
- public IConfiguration Configuration { get; }
- // This method gets called by the runtime. Use this method to add services to the container.
- public void ConfigureServices(IServiceCollection services)
- {
- JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
- services.AddAuthentication(options =>
- {
- options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
- options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
- })
- .AddCookie()
- .AddOpenIdConnect(options =>
- {
- options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
- options.Authority = "https://api.comprobanteselectronicos.go.cr/recepcion/v1/&jsoncallback=?"; // Auth Server
- options.RequireHttpsMetadata = true; // only for development
- options.ClientId = "api-stag"; // client setup in Auth Server
- options.ClientSecret = "";
- options.ResponseType = "code id_token"; // means Hybrid flow
- options.Scope.Add("fiver_auth_api");
- options.Scope.Add("offline_access");
- options.GetClaimsFromUserInfoEndpoint = true;
- options.SaveTokens = true;
- });
- services.AddMvc();
- }
- public void Configure(IApplicationBuilder app,IHostingEnvironment env)
- {
- app.UseAuthentication();
- app.UseMvcWithDefaultRoute();
- }
- [Authorize]
- public class HomeController : Controller
- {
- [AllowAnonymous]
- public IActionResult Index()
- {
- return View();
- }
- public async Task<IActionResult> Movies()
- {
- var accessToken = await HttpContext.GetTokenAsync("access_token");
- var client = new HttpClient();
- client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
- var content = await client.GetStringAsync("https://api.comprobanteselectronicos.go.cr/recepcion-sandbox/v1/&jsoncallback=?");
- var model = JsonConvert.DeserializeObject(content);
- return View(model);
- }
- public async Task Logout()
- {
- await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
- await HttpContext.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme);
- }
Add Comment
Please, Sign In to add comment