Bristol SU Support Package
AuthenticationServiceProvider.php
Go to the documentation of this file.
1 <?php
2 
4 
12 
16 class AuthenticationServiceProvider extends ServiceProvider
17 {
18 
26  public function register()
27  {
28  $this->app->call([$this, 'registerAuthentication']);
29  $this->app->bind(ResourceIdGenerator::class, AuthenticationResourceIdGenerator::class);
30  $this->app->register(PassportServiceProvider::class);
31  }
32 
36  public function boot()
37  {
38  UrlGenerator::macro('getAuthQueryArray', function() {
39  $query = [];
40  if(app(Authentication::class)->getUser() !== null) {
41  $query['u'] = app(Authentication::class)->getUser()->id();
42  }
43  if(app(Authentication::class)->getGroup() !== null) {
44  $query['g'] = app(Authentication::class)->getGroup()->id();
45  }
46  if(app(Authentication::class)->getRole() !== null) {
47  $query['r'] = app(Authentication::class)->getRole()->id();
48  }
49  try {
50  $query['a'] = app(ActivityInstanceResolver::class)->getActivityInstance()->id;
51  } catch (NotInActivityInstanceException $e) {}
52  return $query;
53  });
54  UrlGenerator::macro('getAuthQueryString', function() {
55  return http_build_query(UrlGenerator::getAuthQueryArray(), '', '&', PHP_QUERY_RFC3986);
56  });
57  }
58 
59  public function registerAuthentication(Request $request)
60  {
61  $this->app->bind(Authentication::class, function($app) use ($request) {
62  return ($request->is('api/*') ?
63  $app->make(ApiAuthentication::class) : $app->make(WebRequestAuthentication::class));
64  });
65 
66  }
67 
68 
69 }