AuthorizeRequest.h 2.11 KB
Newer Older
1 2 3 4 5 6 7 8 9
/*****************************************************************************
 * AuthorizeRequest.h : AuthorizeRequest headers
 *
 *****************************************************************************
 * Copyright (C) 2016-2016 VideoLAN
 *
 * Authors: Paweł Wegner <pawel.wegner95@gmail.com>
 *
 * This program is free software; you can redistribute it and/or
Paweł Wegner's avatar
Paweł Wegner committed
10
 * modify it under the terms of the GNU Lesser General Public License
11 12 13 14 15 16
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Paweł Wegner's avatar
Paweł Wegner committed
17
 * GNU Lesser General Public License for more details.
18
 *
Paweł Wegner's avatar
Paweł Wegner committed
19
 * You should have received a copy of the GNU Lesser General Public License
20 21 22 23 24 25 26 27 28
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#ifndef AUTHORIZEREQUEST_H
#define AUTHORIZEREQUEST_H

#include "Request.h"

29 30
#include "IAuth.h"

31 32
namespace cloudstorage {

33
class AuthorizeRequest : public Request<EitherError<void>> {
34
 public:
35
  using Pointer = std::shared_ptr<AuthorizeRequest>;
36 37 38
  using AuthorizeCompleted = std::function<void(EitherError<void>)>;
  using AuthorizationFlow = std::function<void(
      std::shared_ptr<AuthorizeRequest>, AuthorizeCompleted)>;
39

40
  AuthorizeRequest(std::shared_ptr<CloudProvider>, AuthorizationFlow = nullptr);
41 42
  ~AuthorizeRequest();

43
  void oauth2Authorization(AuthorizeCompleted);
44 45
  void sendCancel();
  void cancel();
46
  void set_server(std::shared_ptr<IHttpServer>);
47 48

 private:
49 50
  void resolve(Request::Pointer, AuthorizationFlow callback);

51
  std::string state_;
52
  std::mutex lock_;
53
  bool server_cancelled_;
54
  std::shared_ptr<IHttpServer> auth_server_;
55
};
56

57 58
class SimpleAuthorization : public AuthorizeRequest {
 public:
59
  SimpleAuthorization(std::shared_ptr<CloudProvider>);
60 61 62 63 64
};

}  // namespace cloudstorage

#endif  // AUTHORIZEREQUEST_H