Implicit Flow
For the Implicit Flow grant type, the following example is
provided for demonstration using the WebBrowser control and the
OAuthClient object.
Step 1: Get the access token of the redirect authorization code
by accessing the authorization URL via the WebBrowser control. You
will need to input the user name and password for accessing the
URL.
|
1 2 3 |
ls_Url_token = "https://accounts.google.com/o/oauth2/auth?client_id=" + ls_id + "&redirect_uri=" + ls_redirect +"&scope=" + ls_Scope + "&response_type=token" OpenWithParm ( w_webbrowser, ls_Url_token ) //via the WebBrowser control ls_AccessToken = Message.Stringparm |
Step 2: Get the resource from the resource URL via the access
token.
|
1 2 3 4 5 6 |
OAuthRequest loa_Request ResourceResponse lrr_Response loa_Request.SetAccessToken (access_token) loa_Request.Method = "GET" loa_Request.Url = "https://www.googleapis.com/oauth2/v1/tokeninfo" li_rtn = ioa_Client.requestresource( loa_Request, lrr_Response ) |
The complete code example is as below:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
String ls_id, ls_Scope, ls_Redirect String ls_Body, ls_AccessToken, ls_Url_token Integer li_rtn OAuthClient loa_Client OAuthRequest loa_Request ResourceResponse lrr_Response loa_Client = Create OAuthClient ls_id = "434849452875-6905f1g9rjiargcnqut06afmnn0b0fp7.apps.googleusercontent.com" ls_Scope = "https://www.googleapis.com/auth/youtube" ls_Redirect = "https://www.appeon.com/callback" //Step 1: Get the access token ls_Url_token = "https://accounts.google.com/o/oauth2/auth?client_id=" + ls_id + "&redirect_uri=" + ls_Redirect +"&scope=" + ls_Scope + "&response_type=token" OpenWithParm ( w_webbrowser2,ls_Url_token ) ls_AccessToken = Message.Stringparm If Len ( ls_AccessToken ) < 1 Then Return If Pos( ls_AccessToken, "access_token=" ) < 0 Then return ls_AccessToken = Mid ( ls_AccessToken, Pos( ls_AccessToken, "access_token=" ) + 13) ls_AccessToken = Mid ( ls_AccessToken,1,pos(ls_AccessToken,"&token_type") - 1) //Step 2: Get the RESTful Server resource If Len(ls_AccessToken) > 0 Then loa_Request.SetAccessToken (ls_AccessToken) loa_Request.Method = "GET" loa_Request.Url = "https://www.googleapis.com/oauth2/v1/tokeninfo" li_rtn = loa_Client.requestresource( loa_Request, lrr_Response ) If li_rtn = 1 Then lrr_Response.GetBody(ls_Body) MessageBox ( "Tips", ls_Body ) End If End If If IsValid ( loa_Client ) Then Destroy ( loa_Client ) |
Document get from Powerbuilder help
Thank you for watching.
Subscribe
Login
0 Comments
Oldest