예제 #1
0
		public LoginPage (Authenticator authenticator)
		{
			this.authenticator = authenticator;
			InitializeComponent ();
		}
예제 #2
0
		protected virtual async Task<OAuthAccount> GetAccountFromAuthCode(Authenticator authenticator, string identifier)
		{
			var postData = await authenticator.GetTokenPostData(ClientSecret);
			if (string.IsNullOrWhiteSpace(TokenUrl))
				throw new Exception("Invalid TokenURL");
			var reply = await Client.PostAsync(TokenUrl, new FormUrlEncodedContent(postData));
			var resp = await reply.Content.ReadAsStringAsync();
			var result = Deserialize<OauthResponse>(resp);
			if (!string.IsNullOrEmpty(result.Error))
 				throw new Exception(result.ErrorDescription);

			var account = new OAuthAccount()
			{
				ExpiresIn = result.ExpiresIn,
				Created = DateTime.UtcNow,
				RefreshToken = result.RefreshToken,
				Scope = authenticator.Scope.ToArray(),
				TokenType = result.TokenType,
				Token = result.AccessToken,
				ClientId = ClientId,
				Identifier = identifier,
			};
			return account;
		}
		protected override async Task<OAuthAccount> GetAccountFromAuthCode(Authenticator authenticator, string identifier)
		{
			var account = new OAuthAccount()
			{
				ExpiresIn = (long)(TimeSpan.FromDays(365).TotalSeconds),
				Created = DateTime.UtcNow,
				TokenType = "Bearer",
				Token = authenticator.AuthCode,
				ClientId = ClientId,
				Identifier = identifier,
			};
			return account;
		}