Guest User

Untitled

a guest
Nov 21st, 2017
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. Access Token URL = https://unsitio/web/token
  2. Grant Type = password
  3. Authorization Grants = password
  4. Client Id = nnnnnnnn
  5. Client Secret = [Vacio]
  6. Scope = [Vacio]
  7. Username = hhhhhh@vvvv.ggg.oooo.lll
  8. Password = sssssssss
  9.  
  10. public IConfiguration Configuration { get; }
  11.  
  12. // This method gets called by the runtime. Use this method to add services to the container.
  13.  
  14. public void ConfigureServices(IServiceCollection services)
  15. {
  16. JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
  17.  
  18. services.AddAuthentication(options =>
  19. {
  20. options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
  21. options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
  22. })
  23. .AddCookie()
  24. .AddOpenIdConnect(options =>
  25. {
  26. options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
  27. options.Authority = "https://api.comprobanteselectronicos.go.cr/recepcion/v1/&jsoncallback=?"; // Auth Server
  28. options.RequireHttpsMetadata = true; // only for development
  29. options.ClientId = "api-stag"; // client setup in Auth Server
  30. options.ClientSecret = "";
  31. options.ResponseType = "code id_token"; // means Hybrid flow
  32. options.Scope.Add("fiver_auth_api");
  33. options.Scope.Add("offline_access");
  34. options.GetClaimsFromUserInfoEndpoint = true;
  35. options.SaveTokens = true;
  36. });
  37.  
  38. services.AddMvc();
  39. }
  40.  
  41. public void Configure(IApplicationBuilder app,IHostingEnvironment env)
  42. {
  43. app.UseAuthentication();
  44. app.UseMvcWithDefaultRoute();
  45. }
  46.  
  47. [Authorize]
  48. public class HomeController : Controller
  49. {
  50. [AllowAnonymous]
  51. public IActionResult Index()
  52. {
  53. return View();
  54. }
  55.  
  56. public async Task<IActionResult> Movies()
  57. {
  58. var accessToken = await HttpContext.GetTokenAsync("access_token");
  59.  
  60. var client = new HttpClient();
  61. client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
  62. var content = await client.GetStringAsync("https://api.comprobanteselectronicos.go.cr/recepcion-sandbox/v1/&jsoncallback=?");
  63.  
  64. var model = JsonConvert.DeserializeObject(content);
  65.  
  66. return View(model);
  67. }
  68.  
  69. public async Task Logout()
  70. {
  71. await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
  72. await HttpContext.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme);
  73. }
Add Comment
Please, Sign In to add comment