Пример #1
0
        public static Token FromXElement(XElement element)
        {
            if (element.Element("Server") == null)
                throw new RequiredElementMissingException("Server", element);
            if (element.Element("ResourceOwner") == null)
                throw new RequiredElementMissingException("ResourceOwner", element);

            var server =
                ServersWithAuthorizationCode.GetServerWithAuthorizationCode(new Guid(element.Element("Server").Value));
            var resourceOwner = ResourceOwners.GetResourceOwner(element.Element("ResourceOwner").Value);
            var token = new Token(server, resourceOwner);

            if (element.Element("Expires") != null)
                token.Expires = DateTime.Parse(element.Element("Expires").Value);
            if (element.Element("AccessToken") != null)
                token.AccessToken = element.Element("AccessToken").Value;
            if (element.Element("RefreshToken") != null)
                token.RefreshToken = element.Element("RefreshToken").Value;
            if (element.Element("AuthorizationCode") != null)
                token.AuthorizationCode = element.Element("AuthorizationCode").Value;
            if (element.Element("RedirectUri") != null)
                token.RedirectUri = new Uri(element.Element("RedirectUri").Value);

            return token;
        }
        private void CmdGetAuthorizationCodeClick(object sender, EventArgs e)
        {
            var mock = new Mock<IWebOperationContext> {DefaultValue = DefaultValue.Mock};
            var incommingWebContext = mock.Object;
            mock.SetupAllProperties();

            incommingWebContext.IncomingRequest.UriTemplateMatch.RequestUri = webBrowser1.Url;

            Tuple<ServerWithAuthorizationCode, ResourceOwner> tuple;
            tuple = incommingWebContext.GetCredentialsFromAuthorizationRedirect();
            var server = tuple.Item1;
            var resourceOwner = tuple.Item2;
            _token = Tokens.GetToken(tuple.Item1, tuple.Item2);

            lblAuthorizationCode.Text = _token.AuthorizationCode;

        }
Пример #3
0
 public bool Equals(Token token)
 {
     return !Equals(token, null) &&
            (Server.Guid.Equals(token.Server.Guid) && ResourceOwner.Name.Equals(token.ResourceOwner.Name));
 }