Ejemplo n.º 1
0
    public void APITestRefreshTokenOk()
    {
        var json   = @"
        {
            ""access_token"": ""abc123"",
            ""expires_in"": 12345,
            ""id_token"": ""abcdefg"",
            ""refresh_token"": ""abc321"",
            ""scope"":""profile openid"",
            ""token_type"": ""Bearer""
        }
        ";
        var called = false;

        LineAPI.RefreshAccessToken(result => {
            Assert.True(result.IsSuccess);
            result.MatchOk(token => {
                called = true;
                Assert.AreEqual("abc123", token.Value);
                Assert.AreEqual(12345, token.ExpiresIn);
                Assert.AreEqual("abcdefg", token.IdTokenRaw);
                Assert.AreEqual("abc321", token.RefreshToken);
                Assert.AreEqual("profile openid", token.Scope);
                Assert.AreEqual("Bearer", token.TokenType);
            });
        });

        var identifier = LineAPI.actions.Keys.ToList()[0];

        LineAPI._OnApiOk(CallbackPayload.WrapValue(identifier, json));
        Assert.True(called);
        Assert.IsEmpty(LineAPI.actions);
    }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,LineToken,Detail,onOff")] LineAPI lineAPI)
        {
            /*Check Session */
            var page            = "195";
            var typeofuser      = "";
            var PermisionAction = "";

            // CheckSession
            if (string.IsNullOrEmpty(HttpContext.Session.GetString("Username")))
            {
                Alert("คุณไม่มีสิทธิ์ใช้งานหน้าดังกล่าว", NotificationType.error);
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                typeofuser      = HttpContext.Session.GetString("TypeOfUserId");
                PermisionAction = HttpContext.Session.GetString("PermisionAction");
                if (PermisionHelper.CheckPermision(typeofuser, PermisionAction, page) == false)
                {
                    Alert("คุณไม่มีสิทธิ์ใช้งานหน้าดังกล่าว", NotificationType.error);
                    return(RedirectToAction("Index", "Home"));
                }
            }
            /*Check Session */


            if (ModelState.IsValid)
            {
                _context.Add(lineAPI);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(lineAPI));
        }
Ejemplo n.º 3
0
    public void APITestRefreshTokenError()
    {
        var json   = @"
        {
            ""code"": 123,
            ""message"": ""error""
        }
        ";
        var called = false;

        LineAPI.RefreshAccessToken(result => {
            Assert.True(result.IsFailure);
            result.MatchError(error => {
                called = true;
                Assert.AreEqual(123, error.Code);
                Assert.AreEqual("error", error.Message);
            });
        });

        var identifier = LineAPI.actions.Keys.ToList()[0];

        LineAPI._OnApiError(CallbackPayload.WrapValue(identifier, json));
        Assert.True(called);
        Assert.IsEmpty(LineAPI.actions);
    }
Ejemplo n.º 4
0
    public void APITestGetProfileOk()
    {
        var json   = @"
        {
            ""displayName"": ""testuser"",
            ""userId"": ""user_id"",
            ""pictureUrl"": ""https://example.com/abcd"",
            ""statusMessage"": ""Hi""
        }
        ";
        var called = false;

        LineAPI.GetProfile(result => {
            Assert.True(result.IsSuccess);
            result.MatchOk(profile => {
                called = true;
                Assert.AreEqual("user_id", profile.UserId);
                Assert.AreEqual("testuser", profile.DisplayName);
                Assert.AreEqual("Hi", profile.StatusMessage);
                Assert.AreEqual("https://example.com/abcd", profile.PictureUrl);
                Assert.AreEqual("https://example.com/abcd/large", profile.PictureUrlLarge);
                Assert.AreEqual("https://example.com/abcd/small", profile.PictureUrlSmall);
            });
        });

        var identifier = LineAPI.actions.Keys.ToList()[0];

        LineAPI._OnApiOk(CallbackPayload.WrapValue(identifier, json));
        Assert.True(called);
        Assert.IsEmpty(LineAPI.actions);
    }
Ejemplo n.º 5
0
    public void APITestVerifyAccessTokenOk()
    {
        var json   = @"
        {
            ""client_id"": ""12345678"",
            ""expires_in"": 12345,
            ""scope"": ""profile openid""
        }
        ";
        var called = false;

        LineAPI.VerifyAccessToken(result => {
            Assert.True(result.IsSuccess);
            result.MatchOk(value => {
                called = true;
                Assert.AreEqual(value.ChannelId, "12345678");
                Assert.AreEqual(12345, value.ExpiresIn);
                Assert.AreEqual(value.Scope, "profile openid");
            });
        });

        var identifier = LineAPI.actions.Keys.ToList()[0];

        LineAPI._OnApiOk(CallbackPayload.WrapValue(identifier, json));
        Assert.True(called);
        Assert.IsEmpty(LineAPI.actions);
    }
Ejemplo n.º 6
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,LineToken,Detail,onOff")] LineAPI lineAPI)
        {
            /*Check Session */
            var page            = "196";
            var typeofuser      = "";
            var PermisionAction = "";

            // CheckSession
            if (string.IsNullOrEmpty(HttpContext.Session.GetString("Username")))
            {
                Alert("คุณไม่มีสิทธิ์ใช้งานหน้าดังกล่าว", NotificationType.error);
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                typeofuser      = HttpContext.Session.GetString("TypeOfUserId");
                PermisionAction = HttpContext.Session.GetString("PermisionAction");
                if (PermisionHelper.CheckPermision(typeofuser, PermisionAction, page) == false)
                {
                    Alert("คุณไม่มีสิทธิ์ใช้งานหน้าดังกล่าว", NotificationType.error);
                    return(RedirectToAction("Index", "Home"));
                }
            }
            /*Check Session */


            if (id != lineAPI.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(lineAPI);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LineAPIExists(lineAPI.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(lineAPI));
        }
Ejemplo n.º 7
0
 public void GetFriendshipStatus()
 {
     LineAPI.GetBotFriendshipStatus(result => {
         result.Match(
             value => {
             UpdateRawSection(value);
         },
             error => {
             UpdateRawSection(error);
         }
             );
     });
 }
Ejemplo n.º 8
0
 public void RefreshToken()
 {
     LineAPI.RefreshAccessToken(result => {
         result.Match(
             value => {
             UpdateRawSection(value);
         },
             error => {
             UpdateRawSection(error);
         }
             );
     });
 }
Ejemplo n.º 9
0
 public void VerifyToken()
 {
     LineAPI.VerifyAccessToken(result => {
         result.Match(
             value => {
             UpdateRawSection(value);
         },
             error => {
             UpdateRawSection(error);
         }
             );
     });
 }
Ejemplo n.º 10
0
 public void GetProfile()
 {
     LineAPI.GetProfile(result => {
         result.Match(
             value => {
             StartCoroutine(UpdateProfile(value));
             UpdateRawSection(value);
         },
             error => {
             UpdateRawSection(error);
         }
             );
     });
 }
Ejemplo n.º 11
0
    public void APITestRevokeTokenOk()
    {
        var json   = "{}";
        var called = false;

        LineAPI.RevokeAccessToken(result => {
            called = true;
            Assert.True(result.IsSuccess);
        });

        var identifier = LineAPI.actions.Keys.ToList()[0];

        LineAPI._OnApiOk(CallbackPayload.WrapValue(identifier, json));
        Assert.True(called);
    }
Ejemplo n.º 12
0
    public void APITestGetBotFriendshipStatusOk()
    {
        var json   = @"
        {
            ""friendFlag"": true
        }
        ";
        var called = false;

        LineAPI.GetBotFriendshipStatus(result => {
            Assert.True(result.IsSuccess);
            result.MatchOk(value => {
                called = true;
                Assert.True(value.IsFriend);
            });
        });

        var identifier = LineAPI.actions.Keys.ToList()[0];

        LineAPI._OnApiOk(CallbackPayload.WrapValue(identifier, json));
        Assert.True(called);
        Assert.IsEmpty(LineAPI.actions);
    }
Ejemplo n.º 13
0
    public void LoginTestOk()
    {
        var json   = @"
        {
            ""accessToken"": {
                ""access_token"": ""abc123"",
                ""expires_in"": 12345,
                ""id_token"": ""abcdefg"",
                ""refresh_token"": ""abc321"",
                ""scope"":""profile openid"",
                ""token_type"": ""Bearer""
            },
            ""scope"": ""profile openid"",
            ""userProfile"": {
                ""displayName"": ""testuser"",
                ""userId"": ""user_id"",
                ""pictureUrl"": ""https://example.com/abcd"",
                ""statusMessage"": ""Hi""
            },
            ""friendshipStatusChanged"": true
        }
        ";
        var called = false;

        LineAPI.Login(new string[] { "profile" }, null, result => {
            result.MatchOk(value => {
                called = true;
                Assert.AreEqual("abc123", value.AccessToken.Value);
            });
        });

        var identifier = LineAPI.actions.Keys.ToList()[0];

        LineAPI._OnApiOk(CallbackPayload.WrapValue(identifier, json));
        Assert.True(called);
        Assert.IsEmpty(LineAPI.actions);
    }