Nemiro.OAuth OAuthBase
Nemiro.OAuth OAuth2Client
Nemiro.OAuth.Clients FacebookClient
Namespace: Nemiro.OAuth.Clients
Assembly: Nemiro.OAuth (in Nemiro.OAuth.dll) Version: 1.9.4.725 (1.9.4.725)
The FacebookClient type exposes the following members.
Name | Description | |
---|---|---|
![]() | FacebookClient |
Initializes a new instance of the FacebookClient.
|
Name | Description | |
---|---|---|
![]() | Clone |
Creates a shallow copy of the current object.
(Inherited from OAuthBase.) |
![]() | Clone(NameValueCollection, String) |
Creates a shallow copy of the current object.
(Inherited from OAuthBase.) |
![]() | Equals | (Inherited from Object.) |
![]() | Finalize | (Inherited from Object.) |
![]() | GetAccessToken |
Gets the access token from the remote server.
(Inherited from OAuth2Client.) |
![]() | GetHashCode | (Inherited from Object.) |
![]() | GetSpecifiedTokenOrCurrent |
Returns the specified access token or the current access token.
(Inherited from OAuthBase.) |
![]() | GetType | (Inherited from Object.) |
![]() | GetUserInfo | Obsolete.
Gets the user details via API of the provider.
(Inherited from OAuthBase.) |
![]() | GetUserInfo(AccessToken) |
Gets the user details.
(Overrides OAuthBase GetUserInfo(AccessToken).) |
![]() | MemberwiseClone | (Inherited from Object.) |
![]() | RedirectToAuthorization |
Redirects a client to the Authorization URL.
(Inherited from OAuthBase.) |
![]() | RefreshToken |
Sends a request to refresh the access token.
(Overrides OAuth2Client RefreshToken(AccessToken).) |
![]() | RevokeToken |
Sends a request to revoke the access token.
(Overrides OAuthBase RevokeToken(AccessToken).) |
![]() | ToString | (Inherited from Object.) |
Name | Description | |
---|---|---|
![]() | AccessToken |
Gets or sets an access token.
(Inherited from OAuthBase.) |
![]() | AccessTokenUrl |
Gets or sets the address for the access token.
(Inherited from OAuthBase.) |
![]() | AccessTokenValue |
Gets an access token value.
(Inherited from OAuthBase.) |
![]() | ApplicationId |
Gets or sets the application identifier.
(Inherited from OAuthBase.) |
![]() | ApplicationSecret |
Gets or sets the application secret key.
(Inherited from OAuthBase.) |
![]() | AuthorizationCode |
Gets or sets access code for access token requests.
(Inherited from OAuthBase.) |
![]() | AuthorizationUrl |
Gets the endpoint of the authorization.
(Inherited from OAuth2Client.) |
![]() | AuthorizeUrl |
Gets or sets the base address for login.
(Inherited from OAuthBase.) |
![]() | DefaultScope |
The deault scope.
(Inherited from OAuth2Client.) |
![]() | GrantType |
Gets or sets grant type.
(Inherited from OAuth2Client.) |
![]() | Parameters |
Gets or sets additional query parameters.
(Inherited from OAuthBase.) |
![]() | Password |
Gets or sets password if GrantType is password or client_credentials.
(Inherited from OAuth2Client.) |
![]() | ProviderName |
Unique provider name: Facebook.
(Overrides OAuthBase ProviderName.) |
![]() | ReturnUrl |
Return URL.
(Overrides OAuthBase ReturnUrl.) |
![]() | Scope |
The scope of the access request.
(Inherited from OAuth2Client.) |
![]() | ScopeSeparator |
The separator in the scope list.
(Inherited from OAuth2Client.) |
![]() | State |
Gets or sets unique request identifier.
For clients the value sets is automatically.
(Inherited from OAuthBase.) |
![]() | SupportRefreshToken |
Gets or sets a value indicating whether the current client supports refreshing access token.
(Inherited from OAuthBase.) |
![]() | SupportRevokeToken |
Gets or sets a value indicating whether the current client supports revoking access token.
(Inherited from OAuthBase.) |
![]() | Username |
Gets or sets username if GrantType is password or client_credentials.
(Inherited from OAuth2Client.) |
![]() | Version |
Gets the version of the OAuth protocol.
(Inherited from OAuthBase.) |
Register and Configure a Facebook Application
![]() | Web Management Interface may change over time. Applications registration shown below may differ. If the interface is changed, you need to register the application and get Client ID and Client Secret. For web projects, configure return URLs. If you have any problems with this, please visit issues. If you do not find a solution to your problem, you can create a new question. |
You need to register as developer.
Open the Facebook Developers and Create a New App.
Specify the application name and click the Create App.
In the application dashboard you can found App ID and App Secret, this is Client ID and Client Secret. Use this for creating an instance of the FacebookClient class.
OAuthManager.RegisterClient ( new FacebookClient ( "1435890426686808", "c6057dfae399beee9e8dc46a4182e8fd" ) );
You can use the App ID and App Secret for desktop, mobile and web projects.
The application availability
To manage the status of the application, you must provide contact information.
Enter a contact email on the Settings page.
And now, you can change availability status of the application on the Status & Review page.
Configure application for web projects
For web projects, configure return URLs.
Open the application Settings and click Advanced tab.
You must add the return URLs to the Valid OAuth redirect URIs field of the Security section.
Do not forget to save your changes.
NOTE: If the application will be used for web and desktop, then also add URL: https://www.facebook.com/connect/login_success.html.
NOTE: Enable Client OAuth Login if it's disabled.
For more details, please see Facebook Developer Documentation.
The following example shows how to use the FacebookClient in desktop applications.
To test the example, create a new Windows Forms project with two forms. Insert a Button to the Form1.
public Form1() { InitializeComponent(); button1.Click += new EventHandler(button1_Click); } private void Form1_Load(object sender, EventArgs e) { // facebook client registration OAuthManager.RegisterClient ( new FacebookClient ( // app id "1435890426686808", // app secret "c6057dfae399beee9e8dc46a4182e8fd" ) { // display=popup - to open a popup window Parameters = new NameValueCollection { { "display", "popup" } } } ); } private void button1_Click(object sender, EventArgs e) { var frm = new Form2(); frm.ShowDialog(); }
Insert a WebBrowser to the Form2.
public Form2() { InitializeComponent(); webBrowser1.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted); webBrowser1.Navigate(OAuthWeb.GetAuthorizationUrl("facebook")); } private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { // waiting for results if (e.Url.Query.IndexOf("code=") != -1 || e.Url.Fragment.IndexOf("code=") != -1 || e.Url.Query.IndexOf("oauth_verifier=") != -1) { // is the result, verify var result = OAuthWeb.VerifyAuthorization(e.Url.ToString()); if (result.IsSuccessfully) { // show user info MessageBox.Show ( String.Format ( "User ID: {0}\r\nUsername: {1}\r\nDisplay Name: {2}\r\nE-Mail: {3}", result.UserInfo.UserId, result.UserInfo.UserName, result.UserInfo.DisplayName ?? result.UserInfo.FullName, result.UserInfo.Email ), "Successfully", MessageBoxButtons.OK, MessageBoxIcon.Information ); } else { // show error message MessageBox.Show(result.ErrorInfo.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.Close(); } }
Result of the program is shown in the images below.