Skip to content
This repository has been archived by the owner on Feb 11, 2023. It is now read-only.

Commit

Permalink
v1.5
Browse files Browse the repository at this point in the history
* Added ability to get detailed information about users;
* Changed modifier of the <Client> property. Now it is a public property;
* Updated references to Nemiro.OAuth.
  • Loading branch information
alekseynemiro committed Sep 12, 2016
1 parent 16e5406 commit 5c26bc9
Show file tree
Hide file tree
Showing 38 changed files with 327 additions and 161 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

All notable changes to **Nemiro.OAuth.LoginForms** will be documented in this file.

## [v1.5] - 2016-09-12

### Added
* Added ability to get detailed information about users.

### Changed
* Changed modifier of the `Client` property. Now it is a public property;
* Updated references to [Nemiro.OAuth](https://github.com/alekseynemiro/nemiro.oauth.dll).

## [v1.4.2483] - 2016-08-08

### Changed
Expand Down
8 changes: 4 additions & 4 deletions examples/Net35.Facebook/Facebook.Net35.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Nemiro.OAuth, Version=1.11.35.2477, Culture=neutral, PublicKeyToken=cb06320e362d440b, processorArchitecture=MSIL">
<HintPath>packages\Nemiro.OAuth.1.11.2477\lib\net35\Nemiro.OAuth.dll</HintPath>
<Reference Include="Nemiro.OAuth, Version=1.12.35.2615, Culture=neutral, PublicKeyToken=cb06320e362d440b, processorArchitecture=MSIL">
<HintPath>packages\Nemiro.OAuth.1.12\lib\net35\Nemiro.OAuth.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Nemiro.OAuth.LoginForms, Version=1.4.35.2483, Culture=neutral, PublicKeyToken=2656cfe28099e3f4, processorArchitecture=MSIL">
<HintPath>packages\Nemiro.OAuth.LoginForms.1.4.2483\lib\net35\Nemiro.OAuth.LoginForms.dll</HintPath>
<Reference Include="Nemiro.OAuth.LoginForms, Version=1.5.35.2617, Culture=neutral, PublicKeyToken=2656cfe28099e3f4, processorArchitecture=MSIL">
<HintPath>packages\Nemiro.OAuth.LoginForms.1.5\lib\net35\Nemiro.OAuth.LoginForms.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
4 changes: 2 additions & 2 deletions examples/Net35.Facebook/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Nemiro.OAuth" version="1.11.2477" targetFramework="net35" />
<package id="Nemiro.OAuth.LoginForms" version="1.4.2483" targetFramework="net35" />
<package id="Nemiro.OAuth" version="1.12" targetFramework="net35" />
<package id="Nemiro.OAuth.LoginForms" version="1.5" targetFramework="net35" />
</packages>
26 changes: 19 additions & 7 deletions examples/Net40.Google.Drive/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
// limitations under the License.
// ----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Nemiro.OAuth.LoginForms;
Expand Down Expand Up @@ -55,14 +50,17 @@ private void Form1_Load(object sender, EventArgs e)

private void GetAccessToken()
{
var login = new GoogleLogin("934704666049-129jsvmelksmcmf250ir90aqn8pk4nak.apps.googleusercontent.com", "OS7HZ1cfJnhdIFZ6fUsgamH-", "https://www.googleapis.com/auth/drive");
var login = new GoogleLogin("934704666049-129jsvmelksmcmf250ir90aqn8pk4nak.apps.googleusercontent.com", "OS7HZ1cfJnhdIFZ6fUsgamH-", "https://www.googleapis.com/auth/drive", loadUserInfo: true);
login.Owner = this;
login.ShowDialog();

if (login.IsSuccessfully)
{
Properties.Settings.Default.AccessToken = login.AccessToken.Value;
Properties.Settings.Default.Save();

this.Text = String.Format("{0} (Google Drive)", login.UserInfo.DisplayName ?? login.UserInfo.UserName);

this.GetFiles();
}
else
Expand Down Expand Up @@ -131,7 +129,21 @@ private void GetFiles_Result(RequestResult result)
}
else
{
MessageBox.Show(result.ToString());
if (result["error"]["errors"].Count > 0)
{
if (result["error"]["errors"][0]["reason"].Equals("authError", StringComparison.OrdinalIgnoreCase))
{
this.GetAccessToken();
}
else
{
MessageBox.Show(result["error"]["errors"][0]["message"].ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show(result.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions examples/Net40.Google.Drive/Google.Drive.Net40.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Nemiro.OAuth, Version=1.11.4.2477, Culture=neutral, PublicKeyToken=cb06320e362d440b, processorArchitecture=MSIL">
<HintPath>packages\Nemiro.OAuth.1.11.2477\lib\net40\Nemiro.OAuth.dll</HintPath>
<Reference Include="Nemiro.OAuth, Version=1.12.4.2615, Culture=neutral, PublicKeyToken=cb06320e362d440b, processorArchitecture=MSIL">
<HintPath>packages\Nemiro.OAuth.1.12\lib\net40\Nemiro.OAuth.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Nemiro.OAuth.LoginForms, Version=1.4.4.2483, Culture=neutral, PublicKeyToken=2656cfe28099e3f4, processorArchitecture=MSIL">
<HintPath>packages\Nemiro.OAuth.LoginForms.1.4.2483\lib\net40\Nemiro.OAuth.LoginForms.dll</HintPath>
<Reference Include="Nemiro.OAuth.LoginForms, Version=1.5.4.2617, Culture=neutral, PublicKeyToken=2656cfe28099e3f4, processorArchitecture=MSIL">
<HintPath>packages\Nemiro.OAuth.LoginForms.1.5\lib\net40\Nemiro.OAuth.LoginForms.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
4 changes: 2 additions & 2 deletions examples/Net40.Google.Drive/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@
// Можно задать все значения или принять номер построения и номер редакции по умолчанию,
// используя "*", как показано ниже:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2016.7.11")]
[assembly: AssemblyFileVersion("1.2016.7.11")]
[assembly: AssemblyVersion("1.2016.9.12")]
[assembly: AssemblyFileVersion("1.2016.9.12")]
4 changes: 2 additions & 2 deletions examples/Net40.Google.Drive/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Nemiro.OAuth" version="1.11.2477" targetFramework="net40" />
<package id="Nemiro.OAuth.LoginForms" version="1.4.2483" targetFramework="net40" />
<package id="Nemiro.OAuth" version="1.12" targetFramework="net40" />
<package id="Nemiro.OAuth.LoginForms" version="1.5" targetFramework="net40" />
</packages>
8 changes: 4 additions & 4 deletions examples/Net45.Yandex.Disk/Yandex.Disk.Net45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Nemiro.OAuth, Version=1.11.45.2477, Culture=neutral, PublicKeyToken=cb06320e362d440b, processorArchitecture=MSIL">
<HintPath>packages\Nemiro.OAuth.1.11.2477\lib\net45\Nemiro.OAuth.dll</HintPath>
<Reference Include="Nemiro.OAuth, Version=1.12.45.2615, Culture=neutral, PublicKeyToken=cb06320e362d440b, processorArchitecture=MSIL">
<HintPath>packages\Nemiro.OAuth.1.12\lib\net45\Nemiro.OAuth.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Nemiro.OAuth.LoginForms, Version=1.4.45.2483, Culture=neutral, PublicKeyToken=2656cfe28099e3f4, processorArchitecture=MSIL">
<HintPath>packages\Nemiro.OAuth.LoginForms.1.4.2483\lib\net45\Nemiro.OAuth.LoginForms.dll</HintPath>
<Reference Include="Nemiro.OAuth.LoginForms, Version=1.5.45.2617, Culture=neutral, PublicKeyToken=2656cfe28099e3f4, processorArchitecture=MSIL">
<HintPath>packages\Nemiro.OAuth.LoginForms.1.5\lib\net45\Nemiro.OAuth.LoginForms.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
4 changes: 2 additions & 2 deletions examples/Net45.Yandex.Disk/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Nemiro.OAuth" version="1.11.2477" targetFramework="net45" />
<package id="Nemiro.OAuth.LoginForms" version="1.4.2483" targetFramework="net45" />
<package id="Nemiro.OAuth" version="1.12" targetFramework="net45" />
<package id="Nemiro.OAuth.LoginForms" version="1.5" targetFramework="net45" />
</packages>
24 changes: 14 additions & 10 deletions examples/Net451.Twitter/Form1.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ----------------------------------------------------------------------------
// Copyright © Aleksey Nemiro, 2015. All rights reserved.
// Copyright © Aleksey Nemiro, 2015-2016. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -14,13 +14,7 @@
// limitations under the License.
// ----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Nemiro.OAuth;
using Nemiro.OAuth.LoginForms;
Expand Down Expand Up @@ -55,7 +49,8 @@ private void Form1_Load(object sender, EventArgs e)

private void GetAccessToken()
{
var login = new TwitterLogin(this.ConsumerKey, this.ConsumerSecret);
var login = new TwitterLogin(this.ConsumerKey, this.ConsumerSecret, loadUserInfo: true);

login.Owner = this;
login.ShowDialog();

Expand All @@ -64,6 +59,9 @@ private void GetAccessToken()
Properties.Settings.Default.AccessToken = login.AccessTokenValue;
Properties.Settings.Default.TokenSecret = ((OAuthAccessToken)login.AccessToken).TokenSecret;
Properties.Settings.Default.Save();

this.Text = login.UserInfo.DisplayName ?? login.UserInfo.UserName;

this.GetTweets();
}
else
Expand Down Expand Up @@ -120,7 +118,14 @@ private void GetTweets_Result(RequestResult result)
}
else
{
MessageBox.Show(result.ToString());
string errorMessage = result.ToString();

if (result["errors"].HasValue)
{
errorMessage = String.Join("\r\n", result["errors"].Select(itm => itm["message"].ToString()));
}

MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

Expand All @@ -140,7 +145,6 @@ private OAuthAuthorization GetAuth()
return auth;
}


}

}
6 changes: 3 additions & 3 deletions examples/Net451.Twitter/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Twitter.Net451")]
[assembly: AssemblyCopyright("Copyright © Aleksey Nemiro, 2015")]
[assembly: AssemblyCopyright("Copyright © Aleksey Nemiro, 2015-2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -47,5 +47,5 @@
// Можно задать все значения или принять номера сборки и редакции по умолчанию
// используя "*", как показано ниже:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.2016.9.12")]
[assembly: AssemblyFileVersion("1.2016.9.12")]
8 changes: 4 additions & 4 deletions examples/Net451.Twitter/Twitter.Net451.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Nemiro.OAuth, Version=1.11.451.2477, Culture=neutral, PublicKeyToken=cb06320e362d440b, processorArchitecture=MSIL">
<HintPath>packages\Nemiro.OAuth.1.11.2477\lib\net451\Nemiro.OAuth.dll</HintPath>
<Reference Include="Nemiro.OAuth, Version=1.12.451.2615, Culture=neutral, PublicKeyToken=cb06320e362d440b, processorArchitecture=MSIL">
<HintPath>packages\Nemiro.OAuth.1.12\lib\net451\Nemiro.OAuth.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Nemiro.OAuth.LoginForms, Version=1.4.451.2483, Culture=neutral, PublicKeyToken=2656cfe28099e3f4, processorArchitecture=MSIL">
<HintPath>packages\Nemiro.OAuth.LoginForms.1.4.2483\lib\net451\Nemiro.OAuth.LoginForms.dll</HintPath>
<Reference Include="Nemiro.OAuth.LoginForms, Version=1.5.451.2617, Culture=neutral, PublicKeyToken=2656cfe28099e3f4, processorArchitecture=MSIL">
<HintPath>packages\Nemiro.OAuth.LoginForms.1.5\lib\net451\Nemiro.OAuth.LoginForms.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
4 changes: 2 additions & 2 deletions examples/Net451.Twitter/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Nemiro.OAuth" version="1.11.2477" targetFramework="net451" />
<package id="Nemiro.OAuth.LoginForms" version="1.4.2483" targetFramework="net451" />
<package id="Nemiro.OAuth" version="1.12" targetFramework="net451" />
<package id="Nemiro.OAuth.LoginForms" version="1.5" targetFramework="net451" />
</packages>
36 changes: 31 additions & 5 deletions src/Nemiro.OAuth.LoginForms/Login.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ----------------------------------------------------------------------------
// Copyright © Aleksey Nemiro, 2015. All rights reserved.
// Copyright © Aleksey Nemiro, 2015-2016. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -25,19 +25,27 @@
namespace Nemiro.OAuth.LoginForms
{

/// <summary>
/// The base class for the authorization forms.
/// </summary>
public partial class Login : Form
{

/// <summary>
/// An instance of the OAuth client.
/// </summary>
protected OAuthBase Client { get; set; }
public OAuthBase Client { get; protected set; }

/// <summary>
/// Gets a value indicating whether the current authorization result is successful or not.
/// </summary>
public bool IsSuccessfully { get; protected set; }

/// <summary>
/// Gets user profile.
/// </summary>
public UserInfo UserInfo { get; protected set; }

/// <summary>
/// Gets an instance of the access token.
/// </summary>
Expand Down Expand Up @@ -114,14 +122,19 @@ protected internal string AuthorizationCode
/// </summary>
private bool AutoLogout { get; set; }

/// <summary>
/// Gets or sets a value that indicates the need to load user profile information.
/// </summary>
private bool LoadUserInfo { get; set; }

private WebBrowserCallback Callback = null;

private bool AccessTokenProcessing = false;

private bool Timeout = false;

/// <summary>
/// Initializes a new instance of the <see cref="Login"/> class.
/// Initializes a new instance of the <see cref="Login"/>.
/// </summary>
protected Login()
{
Expand All @@ -135,11 +148,12 @@ protected Login()
/// </summary>
/// <param name="client">Instance of the OAuth client.</param>
/// <param name="autoLogout">Disables saving and restoring authorization cookies in WebBrowser. Default: false.</param>
public Login(OAuthBase client, bool autoLogout = false)
: this()
/// <param name="loadUserInfo">Indicates the need to make a request for recive the user profile or not. Default: false.</param>
public Login(OAuthBase client, bool autoLogout = false, bool loadUserInfo = false) : this()
{
this.Client = client;
this.AutoLogout = autoLogout;
this.LoadUserInfo = loadUserInfo;
this.Text = String.Format(this.Text, this.Client.ProviderName);
this.CanLogin = true;
this.CanLogout = true;
Expand Down Expand Up @@ -213,6 +227,11 @@ private void timer1_Tick(object sender, EventArgs e)
this.webBrowser1_DocumentCompleted(this.webBrowser1, new WebBrowserDocumentCompletedEventArgs(this.webBrowser1.Url));
}

/// <summary>
/// Default callback.
/// </summary>
/// <param name="sender">Sender.</param>
/// <param name="e">Event arguments.</param>
protected internal void DefaultCallback(object sender, WebBrowserCallbackEventArgs e)
{
Debug.WriteLine("Default Callback", "LoginForm");
Expand Down Expand Up @@ -290,6 +309,11 @@ private void GetAccessTokenThread(object args)
try
{
this.IsSuccessfully = this.Client.AccessToken.IsSuccessfully;

if (this.LoadUserInfo)
{
this.UserInfo = this.Client.GetUserInfo();
}
}
catch (Exception ex)
{
Expand Down Expand Up @@ -354,6 +378,7 @@ public void SetProgressImage(Image image)
this.Invoke(new Action(Close));
return;
}

// set dialog result
if (this.IsSuccessfully)
{
Expand All @@ -363,6 +388,7 @@ public void SetProgressImage(Image image)
{
this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
}

// close form
base.Close();
}
Expand Down
Loading

0 comments on commit 5c26bc9

Please sign in to comment.