| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- using Astralis;
- using Inversion;
- namespace Spry.Authorisation {
- public class AuthorisationPipelineComponent : Object, PipelineComponent {
- private Scope scope = inject<Scope>();
- private AuthorisationService authorisation_service = inject<AuthorisationService>();
- public async Astralis.HttpResult process_request (Astralis.HttpContext http_context, Astralis.PipelineContext pipeline_context) throws Error {
- var header = http_context.request.headers.get_any_or_default("Authorization");
- AuthorisationToken token = null;
- if(header != null && header.down().has_prefix ("bearer")) {
- try {
- token = authorisation_service.read_token (header.substring(7).chug().chomp());
- }
- catch (Error e) {
- warning("Encountered error while reading bearer token: " + e.message);
- }
- }
- if(token == null && http_context.request.cookies.has(COOKIE_NAME)) {
- var token_string = http_context.request.cookies.get_any(COOKIE_NAME);
- try {
- token = authorisation_service.read_token(token_string);
- }
- catch (Error e) {
- warning("Encountered error while reading cookie token: " + e.message);
- }
- }
- scope.register_local_scoped<AuthorisationContext>(() => new AuthorisationContext (token));
- return yield pipeline_context.next ();
- }
- }
- }
|