Guest User

Untitled

a guest
Nov 21st, 2017
472
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. Password = sssssssss
  8.  
  9. public IConfiguration Configuration { get; }
  10.  
  11. // This method gets called by the runtime. Use this method to add services to the container.
  12.  
  13. public void ConfigureServices(IServiceCollection services)
  14. {
  15. JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
  16.  
  17. services.AddAuthentication(options =>
  18. {
  19. options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
  20. options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
  21. })
  22. .AddCookie()
  23. .AddOpenIdConnect(options =>
  24. {
  25. options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
  26. options.Authority = "https://api.comprobanteselectronicos.go.cr/recepcion/v1/&jsoncallback=?"; // Auth Server
  27. options.RequireHttpsMetadata = true; // only for development
  28. options.ClientId = "api-stag"; // client setup in Auth Server
  29. options.ClientSecret = "";
  30. options.ResponseType = "code id_token"; // means Hybrid flow
  31. options.Scope.Add("fiver_auth_api");
  32. options.Scope.Add("offline_access");
  33. options.GetClaimsFromUserInfoEndpoint = true;
  34. options.SaveTokens = true;
  35. });
  36.  
  37. services.AddMvc();
  38. }
  39.  
  40. public void Configure(IApplicationBuilder app,IHostingEnvironment env)
  41. {
  42. app.UseAuthentication();
  43. app.UseMvcWithDefaultRoute();
  44. }
  45.  
  46. [Authorize]
  47. public class HomeController : Controller
  48. {
  49. [AllowAnonymous]
  50. public IActionResult Index()
  51. {
  52. return View();
  53. }
  54.  
  55. public async Task<IActionResult> Movies()
  56. {
  57. var accessToken = await HttpContext.GetTokenAsync("access_token");
  58.  
  59. var client = new HttpClient();
  60. client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
  61. var content = await client.GetStringAsync("https://api.comprobanteselectronicos.go.cr/recepcion-sandbox/v1/&jsoncallback=?");
  62.  
  63. var model = JsonConvert.DeserializeObject(content);
  64.  
  65. return View(model);
  66. }
  67.  
  68. public async Task Logout()
  69. {
  70. await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
  71. await HttpContext.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme);
  72. }
Add Comment
Please, Sign In to add comment