예제 #1
0
        public async Task <ApiResponse <EmptyResponse> > SessionClose()
        {
            var uri = new Uri($"{FreeboxApi.ApiInfo.ApiUri}{BaseModuleUri}logout/");

            var response = await PostAsync <object, EmptyResponse>(null, uri);

            this.LoggedIn     = false;
            this.SessionToken = null;
            this.Permissions  = new FreeboxPermissions();

            return(response);
        }
예제 #2
0
        public async Task <ApiResponse <OpenedSession> > SessionOpen(string appSecret = null)
        {
            if (string.IsNullOrWhiteSpace(appSecret) && string.IsNullOrWhiteSpace(this.FreeboxApi.AppInfo.AppToken))
            {
                throw new ArgumentNullException(nameof(appSecret), LocalizedStrings.AppTokenNotProvided);
            }

            if (!string.IsNullOrWhiteSpace(appSecret) && string.IsNullOrWhiteSpace(this.FreeboxApi.AppInfo.AppToken))
            {
                this.FreeboxApi.AppInfo.AppToken = appSecret;
            }

            var appToken = appSecret ?? this.FreeboxApi.AppInfo.AppToken;

            var uri = new Uri($"{FreeboxApi.ApiInfo.ApiUri}{BaseModuleUri}");

            var challengeResponse = await GetAsync <LoginStart>(uri, bypassAutoLogin : true);

            using (var hmac = new HMACSHA1(Encoding.UTF8.GetBytes(appToken)))
            {
                var challengeToReturn = hmac
                                        .ComputeHash(Encoding.UTF8.GetBytes(challengeResponse.Result.Challenge))
                                        .Aggregate("", (s, e) => s + string.Format(CultureInfo.InvariantCulture, "{0:x2}", e), s => s);

                var sessionStart = new SessionStart()
                {
                    AppId    = this.FreeboxApi.AppInfo.AppId,
                    Password = challengeToReturn
                };

                var response = await PostAsync <SessionStart, OpenedSession>(sessionStart, new Uri($"{uri}session/"), bypassAutoLogin : true);

                this.LoggedIn = response.Success;

                this.SessionToken = response.Result.SessionToken;

                this.Permissions = response.Result.Permissions;

                return(response);
            }
        }