issue: var result has access_token & token_id. how do i use this to get user email
here I am using google oauth to transfer user to google website loginto their account by using email&password
Dim urlOAuth As String = "https://accounts.google.com/o/oauth2/auth"
Dim urlGetToken As String = "https://accounts.google.com/o/oauth2/token"
' token url to get user information. need help to get user name or email here
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If String.IsNullOrEmpty(Request.QueryString("id")) = False Then
Dim geturlCode As String = Request.QueryString("code")
Dim WebRequest1 As HttpWebRequest = CType(WebRequest.Create(urlGetToken), HttpWebRequest)
Dim Parameter As String = "code=" & geturlCode & "&client_id=" + clientID & "&client_secret=" + clientSecret & "&redirect_uri=" + redirecturi & "&grant_type=authorization_code"
'Dim byteArray As Byte() = Encoding.UTF8.GetBytes(Parameter)
WebRequest1.Method = "POST"
WebRequest1.ContentType = "application/x-www-form-urlencoded"
' WebRequest1.ContentLength = byteArray.Length
Dim utfenc As UTF8Encoding = New UTF8Encoding()
Dim bytes As Byte() = utfenc.GetBytes(Parameter)
Dim os As Stream = Nothing
Try
WebRequest1.ContentLength = bytes.Length
os = WebRequest1.GetRequestStream()
os.Write(bytes, 0, bytes.Length)
Catch
End Try
Dim WebResponse As HttpWebResponse = CType(WebRequest1.GetResponse(), HttpWebResponse)
Dim responseStream As Stream = WebResponse.GetResponseStream()
Dim responseStreamReader As StreamReader = New StreamReader(responseStream)
' access_token inside result
Dim result = responseStreamReader.ReadToEnd()
End If
End Sub
'use oauth url so user can login in to there google account
Public Sub LoginGoogleB_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LoginGoogleB.Click
Dim Uri As String = urlOAuth &
"?approval_prompt=force" &
"&scope=openid%20email" &
"&response_type=code" &
"&access_type=offline" &
"&client_id=" & clientID &
"&redirect_uri=" & redirecturi
Response.Redirect(Uri)
End Sub