| Thành viên | Trả 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 ...
|
 |