Google oauth2 で Web アプリケーションを認証しようとしています。コードビハインドとして vb.net を使用しています。
最初のステップで、 https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A % にリダイレクトするハイパーリンクを追加しました2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile&state=%2Fprofile&redirect_uri=http%3A%2F%2Flocalhost:2690%2Ftest1.aspx&response_type=code&client_id=XXX.apps.googleusercontent.com
コードからコードを受け取った後、test1.aspx のページ読み込み時にコードを使用しました
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsNullOrEmpty(Request.QueryString("code")) Then
Dim buffer As Byte() = Encoding.UTF8.GetBytes("code=" + Request.QueryString("code") + "&client_id=XXX.apps.googleusercontent.com&client_secret=XXX&redirect_uri=https%3A%2F%2Flocalhost:2690%2Ftest1.aspx&grant_type=authorization_code")
Dim req As HttpWebRequest = WebRequest.Create("https://accounts.google.com/o/oauth2/token")
req.Method = "POST"
req.ContentType = "application/x-www-form-urlencoded"
req.ContentLength = buffer.Length
Dim strm As Stream = req.GetRequestStream()
strm.Write(buffer, 0, buffer.Length)
strm.Close()
Try
Dim res As HttpWebResponse = req.GetResponse()
Response.Write(res.StatusDescription)
Catch wex As WebException
Response.Write(wex.Data.ToString + "<br/>" + wex.InnerException.ToString + "<br/>" + wex.Message + "<br/>" + wex.TargetSite.ToString)
End Try
End If
End Sub
サーバーから不正なリクエストエラーが発生するたびに。私が間違っていることを見つけるのを手伝ってください。dotnetopenauth も使用しようとしましたが、各例は mvc と c# を使用しており、vb.net しか知りません。ご協力いただきありがとうございます…。