(w http.ResponseWriter, req *http.Request)
| 1150 | } |
| 1151 | |
| 1152 | func (o *oauth) implicitHandler(w http.ResponseWriter, req *http.Request) { |
| 1153 | q := req.URL.Query() |
| 1154 | if hash := q.Get("urlhash"); hash == "true" { |
| 1155 | state := q.Get("state") |
| 1156 | if state == "" || state != o.state { |
| 1157 | o.badRequest(w, "Failed to authenticate: missing or invalid state") |
| 1158 | return |
| 1159 | } |
| 1160 | accessToken := q.Get("access_token") |
| 1161 | if accessToken == "" { |
| 1162 | o.badRequest(w, "Failed to authenticate: missing access token") |
| 1163 | return |
| 1164 | } |
| 1165 | |
| 1166 | if o.terminalRedirect != "" { |
| 1167 | http.Redirect(w, req, o.terminalRedirect, http.StatusFound) |
| 1168 | } else { |
| 1169 | o.success(w) |
| 1170 | } |
| 1171 | |
| 1172 | expiresIn, _ := strconv.Atoi(q.Get("expires_in")) |
| 1173 | o.tokCh <- &token{ |
| 1174 | AccessToken: accessToken, |
| 1175 | IDToken: q.Get("id_token"), |
| 1176 | RefreshToken: q.Get("refresh_token"), |
| 1177 | ExpiresIn: expiresIn, |
| 1178 | TokenType: q.Get("token_type"), |
| 1179 | } |
| 1180 | return |
| 1181 | } |
| 1182 | |
| 1183 | w.WriteHeader(http.StatusOK) |
| 1184 | w.Header().Add("Content-Type", "text/html; charset=utf-8") |
| 1185 | w.Write([]byte(`<html><head><title>Processing OAuth Request</title>`)) |
| 1186 | w.Write([]byte(`</head>`)) |
| 1187 | w.Write([]byte(`<script type="text/javascript">`)) |
| 1188 | fmt.Fprintf(w, `function redirect(){var hash = window.location.hash.substr(1); document.location.href = "%s?urlhash=true&"+hash;}`, o.redirectURI) |
| 1189 | w.Write([]byte(`if (window.addEventListener) window.addEventListener("load", redirect, false); else if (window.attachEvent) window.attachEvent("onload", redirect); else window.onload = redirect;`)) |
| 1190 | w.Write([]byte("</script>")) |
| 1191 | w.Write([]byte(`<body><p style='font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 22px; color: #333; width: 400px; margin: 0 auto; text-align: center; line-height: 1.7; padding: 20px;'>`)) |
| 1192 | w.Write([]byte(`<strong style='font-size: 28px; color: #000;'>Success</strong><br />`)) |
| 1193 | w.Write([]byte(`Click <a href="javascript:redirect();">here</a> if your browser does not automatically redirect you`)) |
| 1194 | w.Write([]byte(`</p></body></html>`)) |
| 1195 | } |
| 1196 | |
| 1197 | // Auth returns the OAuth 2.0 authentication url. |
| 1198 | func (o *oauth) Auth() (string, error) { |
no test coverage detected