質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Go

Go(golang)は、Googleで開発されたオープンソースのプログラミング言語です。

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Google App Engine

Google App Engineは、Googleの管理するデータセンター上でウェブアプリケーションの開発が可能なクラウドコンピュータ技術です。Java、Python、Go用にSDKが用意されています。

OAuth

OAuth(Open Authorization)は、APIを通して保護されたリソース(サードパーティのアプリケーション)へアクセスする為のオープンプロトコルです。

OAuth 2.0

OAuth 2.0(Open Authorization 2.0)は、APIを通して保護されたリソース(サードパーティのアプリケーション)へアクセスする為のオープンプロトコルです。

Q&A

0回答

1126閲覧

goapp deploysするとoauthのリンクが表示される

pecchan

総合スコア555

Go

Go(golang)は、Googleで開発されたオープンソースのプログラミング言語です。

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Google App Engine

Google App Engineは、Googleの管理するデータセンター上でウェブアプリケーションの開発が可能なクラウドコンピュータ技術です。Java、Python、Go用にSDKが用意されています。

OAuth

OAuth(Open Authorization)は、APIを通して保護されたリソース(サードパーティのアプリケーション)へアクセスする為のオープンプロトコルです。

OAuth 2.0

OAuth 2.0(Open Authorization 2.0)は、APIを通して保護されたリソース(サードパーティのアプリケーション)へアクセスする為のオープンプロトコルです。

0グッド

0クリップ

投稿2021/12/16 12:00

Googoe App Engine、Go初学者です。

こちらを参考に勉強してます。
デプロイしたら
https://(プロジェクトID).appspot.com/
にて簡易なWebアプリにアクセスできるようになるサンプルです。

ですが、デプロイすると
oauthへのリンクが出力されます。

これはどういう事でしょうか?

app.yaml

yaml

1application: point-viewer-335223 2version: 1 3runtime: go 4api_version: go1 5 6# ルートのみ認証不要 7handlers: 8- url: / 9 script: _go_app 10- url: /.* 11 script: _go_app 12 login: required 13 auth_fail_action: redirect

main.go

go

1// 2// 会員向け点数告知(サンプル版) 3// 4package main 5 6import ( 7 "fmt" 8 "net/http" 9 "strconv" 10 11 "google.golang.org/appengine" 12 "google.golang.org/appengine/datastore" 13 "google.golang.org/appengine/user" 14) 15 16// 会員情報 17type UserInfo struct { 18 UserId string // 会員ID 19 Point int // 点数 20} 21 22// 初期化 23func init() { 24 http.HandleFunc("/", rootPage) 25 http.HandleFunc("/admin", adminPage) 26 http.HandleFunc("/entry", entryAction) 27 http.HandleFunc("/viewer", viewerPage) 28} 29 30// ルートページ(/) 31func rootPage(w http.ResponseWriter, r *http.Request) { 32 w.Header().Set("Content-type", "text/html; charset=utf-8") 33 ctx := appengine.NewContext(r) 34 35 u := user.Current(ctx) // ログイン情報 36 var userView string 37 if u == nil { 38 url, _ := user.LoginURL(ctx, "/") // ログインURL 39 userView = fmt.Sprintf("あなたは、ログインしていません。<a href='%s'>ログイン</a>", url) 40 } else { 41 url, _ := user.LogoutURL(ctx, "/") // ログアウトURL 42 userView = fmt.Sprintf("あなたは、%sさんです。<a href='%s'>ログアウト</a>", u.Email, url) 43 } 44 fmt.Fprintf(w, ` 45 <h1>会員向け点数告知(サンプル版)</h1> 46 47会員向けにインターネットから自身の点数を確認させるWebサービスです。 48 49Google(又はG Suite)ユーザ認証機能を利用しています。 50 %s 51 <hr /> 52 53以下のページはログインが必要です。 54 55<a href="/admin">管理者ページ(会員と点数の登録)</a> 56 57<a href="/viewer">会員ページ(点数の照会)</a> 58 `, userView) 59} 60 61// 管理者ページ(/admin) 62func adminPage(w http.ResponseWriter, r *http.Request) { 63 w.Header().Set("Content-type", "text/html; charset=utf-8") 64 //ctx := appengine.NewContext(r) 65 66 fmt.Fprintf(w, ` 67 <h1>管理者ページ</h1> 68 69ここでは管理者が会員と点数の登録を行います。 70 71サンプル版では単純な上書き登録又は削除のみ可能です。 72 本来は管理者以外のアクセスを制限しますが、サンプル版では制限していません。 73 <hr /> 74 <form action="/entry" method="post"> 75 76■会員ID:<input type="input" name="user-id" /> 77 Googleアカウント(又はG Suite)のメールアドレスを入力します。 78 79■点数:<input type="input" name="point" /> 80 点数を数字で入力します。(空欄:会員IDの削除) 81 <button type="submit">登録</button 82 </form> 83 <hr /> 84 85<a href="/">戻る</a> 86 `) 87} 88 89// 登録アクション(/entry) 90func entryAction(w http.ResponseWriter, r *http.Request) { 91 w.Header().Set("Content-type", "text/html; charset=utf-8") 92 ctx := appengine.NewContext(r) 93 94 id := r.FormValue("user-id") // 会員ID 95 if id == "" { 96 http.Error(w, "会員IDが指定されていません。", http.StatusBadRequest) 97 return 98 } 99 key := datastore.NewKey(ctx, "UserInfo", id, 0, nil) // KEY生成 100 pointStr := r.FormValue("point") // 点数 101 // 点数が未設定なら削除する 102 if pointStr == "" { 103 err := datastore.Delete(ctx, key) // 削除 104 if err != nil { 105 http.Error(w, err.Error(), http.StatusInternalServerError) 106 return 107 } 108 fmt.Fprintf(w, ` 109 110%s を削除しました。 111 112<a href="/admin">戻る</a> 113 `, id) 114 return 115 } 116 // 点数が設定されていれば上書登録する 117 point, err := strconv.Atoi(pointStr) //数値変換 118 if err != nil { 119 http.Error(w, "数値変換エラー", http.StatusBadRequest) 120 return 121 } 122 info := UserInfo{UserId: id, Point: point} 123 _, err = datastore.Put(ctx, key) // 上書き登録 124 if err != nil { 125 http.Error(w, err.Error(), http.StatusInternalServerError) 126 return 127 } 128 fmt.Fprintf(w, ` 129 130登録しました。 131 132会員ID: %s 133 点数: %d点 134 135<a href="/admin">戻る</a> 136 `, info.UserId, info.Point) 137} 138 139// 会員ページ(/viewer) 140func viewerPage(w http.ResponseWriter, r *http.Request) { 141 w.Header().Set("Content-type", "text/html; charset=utf-8") 142 ctx := appengine.NewContext(r) 143 144 u := user.Current(ctx) 145 key := datastore.NewKey(ctx, "UserInfo", u.Email, 0, nil) // KEY生成 146 // 点数の参照 147 var info UserInfo 148 err := datastore.Get(ctx, key, info) // 参照 149 if err != nil { 150 http.Error(w, "あなたは会員登録されていません。", http.StatusNotFound) 151 return 152 } 153 fmt.Fprintf(w, ` 154 <h1>点数の照会</h1> 155 156こんにちは、%sさん 157 158あなたの点数は %d 点です。 159 160<a href="/">戻る</a> 161 `, info.UserId, info.Point) 162}

cmd

1test9999@cloudshell:~/point-viewer (point-viewer-335223)$ goapp deploy 211:45 AM Application: point-viewer-335223; version: 1 311:45 AM Host: appengine.google.com 411:45 AM Starting update of app: point-viewer-335223, version: 1 511:45 AM Getting current resource limits. 6https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F&response_type=code&client_id=550516889912.apps.googleusercontent.com&access_type=offline 7Your browser has been opened to visit: 8 9 https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F&response_type=code&client_id=550516889912.apps.googleusercontent.com&access_type=offline 10 11If your browser is on a different machine then exit and re-run this 12application with the command-line parameter 13 14 --noauth_local_webserver

###試したこと

イメージ説明

リンクをクリックすると、添付画像のように許可画面に飛びます。
ここで許可にすると、遷移しますが、

このサイトにアクセスできませんlocalhost で接続が拒否されました。 次をお試しください 接続を確認する プロキシとファイアウォールを確認する ERR_CONNECTION_REFUSED

になります。

どうすれば
Webアプリを実行できるようになるでしょうか?
分かる方教えてくださると幸いです。
宜しくお願い致します。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問