Google Account Authentication API for Web App -- AuthSub #1 (AuthSubRequest)

另外一個方法 AuthSub,這個有範例可以試一下
我也提供執行過程給大家參考。

但我還是一知半解。很煩~

除了上一篇的火星文之外,

另外一種作法是 AuthSub(~比較簡單易懂)

Google的說明: http://code.google.com/intl/zh-TW/apis/accounts/docs/AuthSub.html

 

 

 

 

運氣很好,有找到相關的文章。http://program.faryne.tw/2007/10/google-account-authentication.html

這篇文章清楚多了,言簡意骸!不廢話,一清二楚~

 

簡單的說,瞭解這些參數以後,照作就對了

先來看看 Google官方說明

AuthSubRequest

Call AuthSubRequest to acquire single-use authentication. AuthSubRequest is called as a URL; make a request to https://www.google.com/accounts/AuthSubRequest with the following query parameters:

 

Parameter          Description
next

(required) URL the user should be redirected to after a successful login(登錄成功後,要導向哪個網站?). This value should be a page on the web application site, and can include query parameters. 

hd

(optional) String value identifying a particular hosted domain account to be accessed (for example, 'mycollege.edu'). Use "default" to specify a regular Google account ('username@gmail.com').

scope

(required) URL identifying the service(s) to be accessed(哪些網站與服務,可以接受存取?); see documentation for the service for the correct value(s). The resulting token enables access to the specified service(s) only. To specify more than one scope, list each one separated with a space (encodes as "%20").

secure

(optional) Boolean flag indicating whether the authentication transaction should issue a secure token (1) or a non-secure token (0). Secure tokens are available to registered applications only.

session

 (optional) Boolean flag indicating whether the one-time-use token may be exchanged for a session token (1) or not (0).

=================================================================

Sample 如下:

把下面的URL,寫成同一行,去執行看看,就知道在作什麼了

https://www.google.com/accounts/AuthSubRequest?
   next=http%3A%2F%2F登錄成功後,要導向哪個網站(網址URL)
   &scope=http%3A%2F%2Fwww.google.com%2Fcalendar%2Ffeeds%2F
     %20http%3A%2F%2Fpicasaweb.google.com%2Fdata
   &session=0
   &secure=0

 註解:上面的各種參數,裡面需要進行編碼。

所以  http://  要改寫成 http%3A%2F%2F

=================================================================

 

廢話少說,來看看執行結果:

1.  把上面的 Sample那一整行URL,放到瀏覽器裡面。執行

     將會到Google的網站,要求登入帳號與密碼

 

 

2.  通過 Google的帳號、密碼認證之後,就會用到「參數scope=

    這裡面的 Google服務網站,會先徵詢你的授權。是否允許別的網站使用你的帳號與相關的權力??

 

 

3.  通過之後,就會使用到「參數next=」,導回這個參數事先寫好的網站了

你會在瀏覽器上面的URL,看見這段文字    例如:http://www.123.com/?token=xxxxxxxxxxxx

 

 

 

 

 

接下來要怎麼用,我又搞不懂了

煩死了! 

Google的技術文章寫得真爛!   找幾個地球人來寫吧~

 

 2009/3/11 補充:

我們獲得的 token,必須放在HTTP Header裡面,關於這部份的用法:

ASP.NET的設計師,請看這2篇:

ASP的設計師,請看:Response.AddHeader方法 --  http://msdn.microsoft.com/en-us/library/ms524327.aspx

 

  

=================================================================

這裡提到的作法,名為 AuthSubRequest

只能使用一次而已,比較不方便。

如果想要跟 Session的用法類似,可以使用另外一種 AuthSubSession的方法

(Google官方說法如下)

The token returned is for a single use only; it lets you make only one request to the referenced Google service for that user. This limitation exists to secure authentication tokens specified in a URL.

If you expect to make multiple calls to the Google service, you will want request a token that can be exchanged for a session token (in AuthSubRequest, set session to "true"). Then use the method AuthSubSessionToken.

 

 請看下一篇文章的介紹...................

 

我將思想傳授他人, 他人之所得,亦無損於我之所有;

猶如一人以我的燭火點燭,光亮與他同在,我卻不因此身處黑暗。----Thomas Jefferson

線上課程教學,遠距教學 (Web Form 約 51hr)  https://dotblogs.com.tw/mis2000lab/2016/02/01/aspnet_online_learning_distance_education_VS2015

線上課程教學,遠距教學 (ASP.NET MVC 約 135hr)  https://dotblogs.com.tw/mis2000lab/2018/08/14/ASPnet_MVC_Online_Learning_MIS2000Lab

 

寫信給我,不要私訊 --  mis2000lab (at) yahoo.com.tw  或  school (at) mis2000lab.net

 (1) 第一天 ASP.NET MVC5 完整影片(5.5小時 / .NET 4.x版)免費試聽。影片 https://youtu.be/9spaHik87-A 

 (2) 第一天 ASP.NET Core MVC 完整影片(3小時 / .NET Core 6.0~8.0)免費試聽。影片 https://youtu.be/TSmwpT-Bx4I 

[學員感言] mis2000lab課程評價 - ASP.NET MVC , WebForm  。 https://mis2000lab.medium.com/%E5%AD%B8%E5%93%A1%E6%84%9F%E8%A8%80-mis2000lab%E8%AA%B2%E7%A8%8B%E8%A9%95%E5%83%B9-asp-net-mvc-webform-77903ce9680b  


ASP.NET遠距教學、線上課程(Web Form + MVC)。 第一天課程, "完整" 試聽。 

.........   facebook社團   https://www.facebook.com/mis2000lab   ......................

.........  YouTube (ASP.NET) 線上教學影片  https://www.youtube.com/channel/UC6IPPf6tvsNG8zX3u1LddvA/

 

Blog文章 "附的範例" 無法下載,請看 https://dotblogs.com.tw/mis2000lab/2016/03/14/2008_2015_mis2000lab_sample_download

請看我們的「售後服務」範圍(嚴格認定)。

...................................................................................................................................................... 

ASP.NET MVC  => .NET Core MVC 線上教學  ...... 第一天課程 完整內容 "免費"讓您評估 / 試聽

[遠距教學、教學影片] ASP.NET (Web Form) 課程 上線了!MIS2000Lab.主講   事先錄好的影片,並非上課側錄!   觀看時,有如「一對一」面對面講課