You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

248 lines
11 KiB

Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
  1. {{template "base/head" .}}
  2. <div class="admin edit authentication">
  3. {{template "admin/navbar" .}}
  4. <div class="ui container">
  5. {{template "base/alert" .}}
  6. <h4 class="ui top attached header">
  7. {{.i18n.Tr "admin.auths.edit"}}
  8. </h4>
  9. <div class="ui attached segment">
  10. <form class="ui form" action="{{.Link}}" method="post">
  11. {{.CsrfTokenHtml}}
  12. <input type="hidden" name="id" value="{{.Source.ID}}">
  13. <div class="inline field">
  14. <label>{{$.i18n.Tr "admin.auths.auth_type"}}</label>
  15. <input type="hidden" id="auth_type" name="type" value="{{.Source.Type}}">
  16. <span>{{.Source.TypeName}}</span>
  17. </div>
  18. <div class="required inline field {{if .Err_Name}}error{{end}}">
  19. <label for="name">{{.i18n.Tr "admin.auths.auth_name"}}</label>
  20. <input id="name" name="name" value="{{.Source.Name}}" autofocus required>
  21. </div>
  22. <!-- LDAP and DLDAP -->
  23. {{if or .Source.IsLDAP .Source.IsDLDAP}}
  24. {{ $cfg:=.Source.LDAP }}
  25. <div class="inline required field {{if .Err_SecurityProtocol}}error{{end}}">
  26. <label>{{.i18n.Tr "admin.auths.security_protocol"}}</label>
  27. <div class="ui selection security-protocol dropdown">
  28. <input type="hidden" id="security_protocol" name="security_protocol" value="{{$cfg.SecurityProtocol}}">
  29. <div class="text">{{$cfg.SecurityProtocolName}}</div>
  30. <i class="dropdown icon"></i>
  31. <div class="menu">
  32. {{range .SecurityProtocols}}
  33. <div class="item" data-value="{{.Type}}">{{.Name}}</div>
  34. {{end}}
  35. </div>
  36. </div>
  37. </div>
  38. <div class="required field">
  39. <label for="host">{{.i18n.Tr "admin.auths.host"}}</label>
  40. <input id="host" name="host" value="{{$cfg.Host}}" placeholder="e.g. mydomain.com" required>
  41. </div>
  42. <div class="required field">
  43. <label for="port">{{.i18n.Tr "admin.auths.port"}}</label>
  44. <input id="port" name="port" value="{{$cfg.Port}}" placeholder="e.g. 636" required>
  45. </div>
  46. {{if .Source.IsLDAP}}
  47. <div class="field">
  48. <label for="bind_dn">{{.i18n.Tr "admin.auths.bind_dn"}}</label>
  49. <input id="bind_dn" name="bind_dn" value="{{$cfg.BindDN}}" placeholder="e.g. cn=Search,dc=mydomain,dc=com">
  50. </div>
  51. <input class="fake" type="password">
  52. <div class="field">
  53. <label for="bind_password">{{.i18n.Tr "admin.auths.bind_password"}}</label>
  54. <input id="bind_password" name="bind_password" type="password" value="{{$cfg.BindPassword}}">
  55. <p class="help text red">{{.i18n.Tr "admin.auths.bind_password_helper"}}</p>
  56. </div>
  57. <div class="required field">
  58. <label for="user_base">{{.i18n.Tr "admin.auths.user_base"}}</label>
  59. <input id="user_base" name="user_base" value="{{$cfg.UserBase}}" placeholder="e.g. ou=Users,dc=mydomain,dc=com" required>
  60. </div>
  61. {{end}}
  62. {{if .Source.IsDLDAP}}
  63. <div class="required field">
  64. <label for="user_dn">{{.i18n.Tr "admin.auths.user_dn"}}</label>
  65. <input id="user_dn" name="user_dn" value="{{$cfg.UserDN}}" placeholder="e.g. uid=%s,ou=Users,dc=mydomain,dc=com" required>
  66. </div>
  67. {{end}}
  68. <div class="required field">
  69. <label for="filter">{{.i18n.Tr "admin.auths.filter"}}</label>
  70. <input id="filter" name="filter" value="{{$cfg.Filter}}" placeholder="e.g. (&(objectClass=posixAccount)(uid=%s))" required>
  71. </div>
  72. <div class="field">
  73. <label for="admin_filter">{{.i18n.Tr "admin.auths.admin_filter"}}</label>
  74. <input id="admin_filter" name="admin_filter" value="{{$cfg.AdminFilter}}">
  75. </div>
  76. <div class="field">
  77. <label for="attribute_username">{{.i18n.Tr "admin.auths.attribute_username"}}</label>
  78. <input id="attribute_username" name="attribute_username" value="{{$cfg.AttributeUsername}}" placeholder="{{.i18n.Tr "admin.auths.attribute_username_placeholder"}}">
  79. </div>
  80. <div class="field">
  81. <label for="attribute_name">{{.i18n.Tr "admin.auths.attribute_name"}}</label>
  82. <input id="attribute_name" name="attribute_name" value="{{$cfg.AttributeName}}">
  83. </div>
  84. <div class="field">
  85. <label for="attribute_surname">{{.i18n.Tr "admin.auths.attribute_surname"}}</label>
  86. <input id="attribute_surname" name="attribute_surname" value="{{$cfg.AttributeSurname}}">
  87. </div>
  88. <div class="required field">
  89. <label for="attribute_mail">{{.i18n.Tr "admin.auths.attribute_mail"}}</label>
  90. <input id="attribute_mail" name="attribute_mail" value="{{$cfg.AttributeMail}}" placeholder="e.g. mail" required>
  91. </div>
  92. {{if .Source.IsLDAP}}
  93. <div class="inline field">
  94. <div class="ui checkbox">
  95. <label><strong>{{.i18n.Tr "admin.auths.attributes_in_bind"}}</strong></label>
  96. <input name="attributes_in_bind" type="checkbox" {{if $cfg.AttributesInBind}}checked{{end}}>
  97. </div>
  98. </div>
  99. {{end}}
  100. {{end}}
  101. <!-- SMTP -->
  102. {{if .Source.IsSMTP}}
  103. {{ $cfg:=.Source.SMTP }}
  104. <div class="inline required field">
  105. <label>{{.i18n.Tr "admin.auths.smtp_auth"}}</label>
  106. <div class="ui selection type dropdown">
  107. <input type="hidden" id="smtp_auth" name="smtp_auth" value="{{$cfg.Auth}}" required>
  108. <div class="text">{{$cfg.Auth}}</div>
  109. <i class="dropdown icon"></i>
  110. <div class="menu">
  111. {{range .SMTPAuths}}
  112. <div class="item" data-value="{{.}}">{{.}}</div>
  113. {{end}}
  114. </div>
  115. </div>
  116. </div>
  117. <div class="required field">
  118. <label for="smtp_host">{{.i18n.Tr "admin.auths.smtphost"}}</label>
  119. <input id="smtp_host" name="smtp_host" value="{{$cfg.Host}}" required>
  120. </div>
  121. <div class="required field">
  122. <label for="smtp_port">{{.i18n.Tr "admin.auths.smtpport"}}</label>
  123. <input id="smtp_port" name="smtp_port" value="{{$cfg.Port}}" required>
  124. </div>
  125. <div class="field">
  126. <label for="allowed_domains">{{.i18n.Tr "admin.auths.allowed_domains"}}</label>
  127. <input id="allowed_domains" name="allowed_domains" value="{{$cfg.AllowedDomains}}">
  128. <p class="help">{{.i18n.Tr "admin.auths.allowed_domains_helper"}}</p>
  129. </div>
  130. {{end}}
  131. <!-- PAM -->
  132. {{if .Source.IsPAM}}
  133. {{ $cfg:=.Source.PAM }}
  134. <div class="required field">
  135. <label for="pam_service_name">{{.i18n.Tr "admin.auths.pam_service_name"}}</label>
  136. <input id="pam_service_name" name="pam_service_name" value="{{$cfg.ServiceName}}" required>
  137. </div>
  138. {{end}}
  139. <!-- OAuth2 -->
  140. {{if .Source.IsOAuth2}}
  141. {{ $cfg:=.Source.OAuth2 }}
  142. <div class="inline required field">
  143. <label>{{.i18n.Tr "admin.auths.oauth2_provider"}}</label>
  144. <div class="ui selection type dropdown">
  145. <input type="hidden" id="oauth2_provider" name="oauth2_provider" value="{{$cfg.Provider}}" required>
  146. <div class="text">{{.CurrentOAuth2Provider.DisplayName}}</div>
  147. <i class="dropdown icon"></i>
  148. <div class="menu">
  149. {{range $key, $value := .OAuth2Providers}}
  150. <div class="item" data-value="{{$key}}">{{$value.DisplayName}}</div>
  151. {{end}}
  152. </div>
  153. </div>
  154. </div>
  155. <div class="required field">
  156. <label for="oauth2_key">{{.i18n.Tr "admin.auths.oauth2_clientID"}}</label>
  157. <input id="oauth2_key" name="oauth2_key" value="{{$cfg.ClientID}}" required>
  158. </div>
  159. <div class="required field">
  160. <label for="oauth2_secret">{{.i18n.Tr "admin.auths.oauth2_clientSecret"}}</label>
  161. <input id="oauth2_secret" name="oauth2_secret" value="{{$cfg.ClientSecret}}" required>
  162. </div>
  163. <div class="open_id_connect_auto_discovery_url required field">
  164. <label for="open_id_connect_auto_discovery_url">{{.i18n.Tr "admin.auths.openIdConnectAutoDiscoveryURL"}}</label>
  165. <input id="open_id_connect_auto_discovery_url" name="open_id_connect_auto_discovery_url" value="{{$cfg.OpenIDConnectAutoDiscoveryURL}}">
  166. </div>
  167. <div class="oauth2_use_custom_url inline field">
  168. <div class="ui checkbox">
  169. <label><strong>{{.i18n.Tr "admin.auths.oauth2_use_custom_url"}}</strong></label>
  170. <input id="oauth2_use_custom_url" name="oauth2_use_custom_url" type="checkbox" {{if $cfg.CustomURLMapping}}checked{{end}}>
  171. </div>
  172. </div>
  173. <div class="oauth2_use_custom_url_field oauth2_auth_url required field">
  174. <label for="oauth2_auth_url">{{.i18n.Tr "admin.auths.oauth2_authURL"}}</label>
  175. <input id="oauth2_auth_url" name="oauth2_auth_url" value="{{if $cfg.CustomURLMapping}}{{$cfg.CustomURLMapping.AuthURL}}v{{end}}">
  176. </div>
  177. <div class="oauth2_use_custom_url_field oauth2_token_url required field">
  178. <label for="oauth2_token_url">{{.i18n.Tr "admin.auths.oauth2_tokenURL"}}</label>
  179. <input id="oauth2_token_url" name="oauth2_token_url" value="{{if $cfg.CustomURLMapping}}{{$cfg.CustomURLMapping.TokenURL}}{{end}}">
  180. </div>
  181. <div class="oauth2_use_custom_url_field oauth2_profile_url required field">
  182. <label for="oauth2_profile_url">{{.i18n.Tr "admin.auths.oauth2_profileURL"}}</label>
  183. <input id="oauth2_profile_url" name="oauth2_profile_url" value="{{if $cfg.CustomURLMapping}}{{$cfg.CustomURLMapping.ProfileURL}}{{end}}">
  184. </div>
  185. <div class="oauth2_use_custom_url_field oauth2_email_url required field">
  186. <label for="oauth2_email_url">{{.i18n.Tr "admin.auths.oauth2_emailURL"}}</label>
  187. <input id="oauth2_email_url" name="oauth2_email_url" value="{{if $cfg.CustomURLMapping}}{{$cfg.CustomURLMapping.EmailURL}}{{end}}">
  188. </div>
  189. {{if .OAuth2DefaultCustomURLMappings}}{{range $key, $value := .OAuth2DefaultCustomURLMappings}}
  190. <input id="{{$key}}_token_url" value="{{$value.TokenURL}}" type="hidden" />
  191. <input id="{{$key}}_auth_url" value="{{$value.AuthURL}}" type="hidden" />
  192. <input id="{{$key}}_profile_url" value="{{$value.ProfileURL}}" type="hidden" />
  193. <input id="{{$key}}_email_url" value="{{$value.EmailURL}}" type="hidden" />
  194. {{end}}{{end}}
  195. {{end}}
  196. <div class="inline field {{if not .Source.IsSMTP}}hide{{end}}">
  197. <div class="ui checkbox">
  198. <label><strong>{{.i18n.Tr "admin.auths.enable_tls"}}</strong></label>
  199. <input name="tls" type="checkbox" {{if .Source.UseTLS}}checked{{end}}>
  200. </div>
  201. </div>
  202. <div class="has-tls inline field {{if not .HasTLS}}hide{{end}}">
  203. <div class="ui checkbox">
  204. <label><strong>{{.i18n.Tr "admin.auths.skip_tls_verify"}}</strong></label>
  205. <input name="skip_verify" type="checkbox" {{if .Source.SkipVerify}}checked{{end}}>
  206. </div>
  207. </div>
  208. {{if .Source.IsLDAP}}
  209. <div class="inline field">
  210. <div class="ui checkbox">
  211. <label><strong>{{.i18n.Tr "admin.auths.syncenabled"}}</strong></label>
  212. <input name="is_sync_enabled" type="checkbox" {{if .Source.IsSyncEnabled}}checked{{end}}>
  213. </div>
  214. </div>
  215. {{end}}
  216. <div class="inline field">
  217. <div class="ui checkbox">
  218. <label><strong>{{.i18n.Tr "admin.auths.activated"}}</strong></label>
  219. <input name="is_active" type="checkbox" {{if .Source.IsActived}}checked{{end}}>
  220. </div>
  221. </div>
  222. <div class="field">
  223. <button class="ui green button">{{.i18n.Tr "admin.auths.update"}}</button>
  224. <div class="ui red button delete-button" data-url="{{$.Link}}/delete" data-id="{{.Source.ID}}">{{.i18n.Tr "admin.auths.delete"}}</div>
  225. </div>
  226. </form>
  227. </div>
  228. </div>
  229. </div>
  230. <div class="ui small basic delete modal">
  231. <div class="ui icon header">
  232. <i class="trash icon"></i>
  233. {{.i18n.Tr "admin.auths.delete_auth_title"}}
  234. </div>
  235. <div class="content">
  236. <p>{{.i18n.Tr "admin.auths.delete_auth_desc"}}</p>
  237. </div>
  238. {{template "base/delete_modal_actions" .}}
  239. </div>
  240. {{template "base/footer" .}}