Diễn đàn    Các Projects Dotnetnuke (DNN)    Đăng nhập với Google plus trên C# asp.net

Thành viênTrả lời
aspnet

Lập trình không biên giới
608  bài
1-6-2018 10:47:42
Tạo tài khoản đăng nhập tại địa chỉ : https://console.developers.google.com/

Chúng ta sẽ có bộ 2 thông tin :

client_id
client_secret

Thêm đường dẫn Url về trang xử lý dữ liệu của mình. Trong ví dụ này là :
string redirection_url = "http://localhost:52499/Login.aspx";


Gọi yêu cầu xác thực đến địa chỉ
string url = "https://accounts.google.com/o/oauth2/v2/auth?scope=profile&include_granted_scopes=true&redirect_uri=" + redirection_url + "&response_type=code&client_id=" + clientid + "";

Trong trang xử lý kết quả trả về ta viết :

string url = "https://accounts.google.com/o/oauth2/token";
truyền tham số
string poststring = @"grant_type=authorization_code&code=" + code + "&client_id=" + clientid + "&client_secret=" + clientsecret + "&redirect_uri=" + redirection_url + "";

trả về ta sẽ có token của google, tiếp tục xử lý token của google sẽ cho ta các thông tin khác.


GetuserProfile(obj.access_token);
dưới đây là hàm GetuserProfile
========
string url = "https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=" + accesstoken + "";
WebRequest request = WebRequest.Create(url);
request.Credentials = CredentialCache.DefaultCredentials;
WebResponse response = request.GetResponse();
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
reader.Close();
response.Close();
txt.Text = responseFromServer;

==================
Để logout chúng ta dùng:
string url = "https://www.google.com/accounts/Logout?continue=https://appengine.google.com/_ah/logout?continue=http://localhost:52499/";
Response.Redirect(url);
---
Cây sẽ cho lộc và cây sẽ cho hoa ...
 
aspnet

Lập trình không biên giới
608  bài
1-6-2018 10:49:55
http://coder.awas.vn/downloads.ashx?id=547b5cd8a09442829d6561e175682ea2

Bản mã nguồn này viết trên Visual studio 2005, asp.net ver2.0
Tức là nếu build trên asp.net ver 3.5 hay 4.0 đều chạy ngon, không kế thừa thư viện nào khác. Hoàn toàn code send request, get response stream, và xử lý stream
---
Cây sẽ cho lộc và cây sẽ cho hoa ...
 

Chủ đề gần đây :

Cùng loại :

Tên file Mô tả chi tiết Ngày
NWeb.zip (1) Module đơn giản Newsweb trên Dotnetnuke v10.x.x.x10/18/2025 8:08:11 AM
vspforum.zip (11) Ma nguon vspforum ngay xua4/18/2023 6:38:37 AM
pdfjs.rar (2) pdfjs 2017 : hiển thị tốt trên iphone 11, 12, 13 không lỗi, bản 2012 sẽ lỗi trên iphone6/21/2022 11:52:48 AM
pdfjs2.rar (2) Xem file pdf bằng viewer.hml cua pdfjs (thư viện chuẩn mozilla) 2012. https://mozilla.github.io/pdf.js/getting_started/#download có thể download bản prebuild tại đây6/21/2022 11:52:04 AM
runner.zip (0) using three.js, orbitcontrol to view an object move random on map. Di chuyển 1 đồ vật ngẫu nhiên trên bản đồ, sử dụng với demo nhân viên di chuyển trong văn phòng. Toàn js download về là chạy12/5/2019 5:55:14 PM
gmap.zip (1) google map + marker7/17/2019 2:25:05 PM
vinsmarthomeservice.zip (1) java post json to api, use AsyncTask, event listener7/9/2019 5:00:10 PM
fblogin.zip (0) Login facebook bang javascript SDK7/9/2019 9:16:37 AM
autocomplete-location.zip (2) autocomplete location geo from google place, html + js7/4/2019 4:37:55 PM
WebAPI.zip (8) api for android access db (v1.0.0)7/4/2019 9:14:17 AM