mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Integrate OAuth2 Provider (#5378)
This commit is contained in:
		
				
					committed by
					
						
						techknowlogick
					
				
			
			
				
	
			
			
			
						parent
						
							9d3732dfd5
						
					
				
				
					commit
					e777c6bdc6
				
			
							
								
								
									
										31
									
								
								templates/user/auth/grant.tmpl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								templates/user/auth/grant.tmpl
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
			
		||||
{{template "base/head" .}}
 | 
			
		||||
<div class="ui one column stackable center aligned page grid oauth2-authorize-application-box">
 | 
			
		||||
	<div class="column seven wide">
 | 
			
		||||
		<div class="ui middle centered raised segments">
 | 
			
		||||
			<h3 class="ui top attached header">
 | 
			
		||||
				{{.i18n.Tr "auth.authorize_title" .Application.Name}}
 | 
			
		||||
			</h3>
 | 
			
		||||
			<div class="ui attached segment">
 | 
			
		||||
				{{template "base/alert" .}}
 | 
			
		||||
				<p>
 | 
			
		||||
					<b>{{.i18n.Tr "auth.authorize_application_description"}}</b><br/>
 | 
			
		||||
					{{.i18n.Tr "auth.authorize_application_created_by" .ApplicationUserLink | Str2html}}
 | 
			
		||||
				</p>
 | 
			
		||||
			</div>
 | 
			
		||||
			<div class="ui attached segment">
 | 
			
		||||
				<p>{{.i18n.Tr "auth.authroize_redirect_notice" .ApplicationRedirectDomainHTML | Str2html}}</p>
 | 
			
		||||
			</div>
 | 
			
		||||
			<div class="ui attached segment">
 | 
			
		||||
				<form method="post" action="{{.AppSubUrl}}/login/oauth/grant">
 | 
			
		||||
					{{.CsrfTokenHtml}}
 | 
			
		||||
					<input type="hidden" name="client_id" value="{{.Application.ClientID}}">
 | 
			
		||||
					<input type="hidden" name="state" value="{{.State}}">
 | 
			
		||||
					<input type="hidden" name="redirect_uri" value="{{.RedirectURI}}">
 | 
			
		||||
					<input type="submit" id="authorize-app" value="{{.i18n.Tr "auth.authorize_application"}}" class="ui red inline button"/>
 | 
			
		||||
					<a href="{{.RedirectURI}}" class="ui basic primary inline button">Cancel</a>
 | 
			
		||||
				</form>
 | 
			
		||||
			</div>
 | 
			
		||||
		</div>
 | 
			
		||||
	</div>
 | 
			
		||||
</div>
 | 
			
		||||
{{template "base/footer" .}}
 | 
			
		||||
							
								
								
									
										16
									
								
								templates/user/auth/grant_error.tmpl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								templates/user/auth/grant_error.tmpl
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
			
		||||
{{template "base/head" .}}
 | 
			
		||||
{{if .IsRepo}}<div class="repository">{{template "repo/header" .}}</div>{{end}}
 | 
			
		||||
<div class="ui one column stackable center aligned page grid oauth2-authorize-application-box">
 | 
			
		||||
	<div class="column seven wide">
 | 
			
		||||
		<div class="ui middle centered raised segments">
 | 
			
		||||
			<h1 class="ui top attached header">
 | 
			
		||||
				{{.i18n.Tr "auth.authorization_failed" }}
 | 
			
		||||
			</h1>
 | 
			
		||||
			<h3 class="ui attached segment">{{.Error.ErrorDescription}}</h3>
 | 
			
		||||
			<div class="ui attached segment">
 | 
			
		||||
				<p>{{.i18n.Tr "auth.authorization_failed_desc"}}</p>
 | 
			
		||||
			</div>
 | 
			
		||||
		</div>
 | 
			
		||||
	</div>
 | 
			
		||||
</div>
 | 
			
		||||
{{template "base/footer" .}}
 | 
			
		||||
@@ -45,6 +45,10 @@
 | 
			
		||||
				</button>
 | 
			
		||||
			</form>
 | 
			
		||||
		</div>
 | 
			
		||||
 | 
			
		||||
		{{if .EnableOAuth2}}
 | 
			
		||||
			{{template "user/settings/applications_oauth2" .}}
 | 
			
		||||
		{{end}}
 | 
			
		||||
	</div>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										58
									
								
								templates/user/settings/applications_oauth2.tmpl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								templates/user/settings/applications_oauth2.tmpl
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,58 @@
 | 
			
		||||
<h4 class="ui top attached header">
 | 
			
		||||
	{{.i18n.Tr "settings.manage_oauth2_applications"}}
 | 
			
		||||
</h4>
 | 
			
		||||
<div class="ui attached segment">
 | 
			
		||||
	<div class="ui key list">
 | 
			
		||||
		<div class="item">
 | 
			
		||||
			{{.i18n.Tr "settings.oauth2_application_create_description"}}
 | 
			
		||||
		</div>
 | 
			
		||||
		{{range $app := .Applications}}
 | 
			
		||||
			<div class="item">
 | 
			
		||||
				<div class="right floated content">
 | 
			
		||||
					<a href="{{$.Link}}/oauth2/{{$app.ID}}" class="ui primary tiny icon button">
 | 
			
		||||
						<i class="pencil alternate icon"></i>
 | 
			
		||||
						{{$.i18n.Tr "settings.oauth2_application_edit"}}
 | 
			
		||||
					</a>
 | 
			
		||||
					<button class="ui red tiny button delete-button" id="remove-gitea-oauth2-application"
 | 
			
		||||
							data-url="{{AppSubUrl}}/user/settings/applications/oauth2/delete"
 | 
			
		||||
							data-id="{{$app.ID}}">
 | 
			
		||||
						{{$.i18n.Tr "settings.delete_key"}}
 | 
			
		||||
					</button>
 | 
			
		||||
				</div>
 | 
			
		||||
				<div class="content">
 | 
			
		||||
					<strong>{{$app.Name}}</strong>
 | 
			
		||||
				</div>
 | 
			
		||||
			</div>
 | 
			
		||||
		{{end}}
 | 
			
		||||
	</div>
 | 
			
		||||
</div>
 | 
			
		||||
<div class="ui attached bottom segment">
 | 
			
		||||
	<h5 class="ui top header">
 | 
			
		||||
		{{.i18n.Tr "settings.create_oauth2_application" }}
 | 
			
		||||
	</h5>
 | 
			
		||||
	<form class="ui form ignore-dirty" action="{{.Link}}/oauth2" method="post">
 | 
			
		||||
		{{.CsrfTokenHtml}}
 | 
			
		||||
		<div class="field {{if .Err_AppName}}error{{end}}">
 | 
			
		||||
			<label for="application-name">{{.i18n.Tr "settings.oauth2_application_name"}}</label>
 | 
			
		||||
			<input id="application-name" name="application_name" value="{{.application_name}}" required>
 | 
			
		||||
		</div>
 | 
			
		||||
		<div class="field {{if .Err_RedirectURI}}error{{end}}">
 | 
			
		||||
			<label for="redirect-uri">{{.i18n.Tr "settings.oauth2_redirect_uri"}}</label>
 | 
			
		||||
			<input type="url" name="redirect_uri" id="redirect-uri">
 | 
			
		||||
		</div>
 | 
			
		||||
		<button class="ui green button">
 | 
			
		||||
			{{.i18n.Tr "settings.create_oauth2_application_button"}}
 | 
			
		||||
		</button>
 | 
			
		||||
	</form>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<div class="ui small basic delete modal" id="remove-gitea-oauth2-application">
 | 
			
		||||
	<div class="ui icon header">
 | 
			
		||||
		<i class="trash icon"></i>
 | 
			
		||||
		{{.i18n.Tr "settings.remove_oauth2_application"}}
 | 
			
		||||
	</div>
 | 
			
		||||
	<div class="content">
 | 
			
		||||
		<p>{{.i18n.Tr "settings.oauth2_application_remove_description"}}</p>
 | 
			
		||||
	</div>
 | 
			
		||||
	{{template "base/delete_modal_actions" .}}
 | 
			
		||||
</div>
 | 
			
		||||
							
								
								
									
										66
									
								
								templates/user/settings/applications_oauth2_edit.tmpl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								templates/user/settings/applications_oauth2_edit.tmpl
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,66 @@
 | 
			
		||||
{{template "base/head" .}}
 | 
			
		||||
<div class="user settings applications">
 | 
			
		||||
	{{template "user/settings/navbar" .}}
 | 
			
		||||
	<div class="ui container">
 | 
			
		||||
		{{template "base/alert" .}}
 | 
			
		||||
		<h4 class="ui top attached header">
 | 
			
		||||
			{{.i18n.Tr "settings.edit_oauth2_application"}}
 | 
			
		||||
		</h4>
 | 
			
		||||
		<div class="ui attached segment">
 | 
			
		||||
			{{template "base/alert" .}}
 | 
			
		||||
			<p>{{.i18n.Tr "settings.oauth2_application_create_description"}}</p>
 | 
			
		||||
		</div>
 | 
			
		||||
		<div class="ui attached segment form ignore-dirty">
 | 
			
		||||
			{{.CsrfTokenHtml}}
 | 
			
		||||
			<div class="field">
 | 
			
		||||
				<label for="client-id">{{.i18n.Tr "settings.oauth2_client_id"}}</label>
 | 
			
		||||
				<input id="client-id" readonly value="{{.App.ClientID}}">
 | 
			
		||||
			</div>
 | 
			
		||||
			{{if .ClientSecret}}
 | 
			
		||||
				<div class="field">
 | 
			
		||||
					<label for="client-secret">{{.i18n.Tr "settings.oauth2_client_secret"}}</label>
 | 
			
		||||
					<input id="client-secret" type="text" readonly value="{{.ClientSecret}}">
 | 
			
		||||
				</div>
 | 
			
		||||
			{{else}}
 | 
			
		||||
				<div class="field">
 | 
			
		||||
					<label for="client-secret">{{.i18n.Tr "settings.oauth2_client_secret"}}</label>
 | 
			
		||||
					<input id="client-secret" type="password" readonly value="averysecuresecret">
 | 
			
		||||
				</div>
 | 
			
		||||
			{{end}}
 | 
			
		||||
			<div class="item">
 | 
			
		||||
				<!-- TODO add regenerate secret functionality */ -->
 | 
			
		||||
				{{.i18n.Tr "settings.oauth2_regenerate_secret_hint"}}
 | 
			
		||||
				<a onclick="alert('Not yet implemented.')">{{.i18n.Tr "settings.oauth2_regenerate_secret"}}</a>
 | 
			
		||||
			</div>
 | 
			
		||||
		</div>
 | 
			
		||||
		<div class="ui attached bottom segment">
 | 
			
		||||
			<form class="ui form ignore-dirty" action="{{$.AppSubURL}}/user/settings/applications/oauth2/{{.App.ID}}" method="post">
 | 
			
		||||
				{{.CsrfTokenHtml}}
 | 
			
		||||
				<div class="field {{if .Err_AppName}}error{{end}}">
 | 
			
		||||
					<label for="application-name">{{.i18n.Tr "settings.oauth2_application_name"}}</label>
 | 
			
		||||
					<input id="application-name" value="{{.App.Name}}" name="application_name" required>
 | 
			
		||||
				</div>
 | 
			
		||||
				<div class="field {{if .Err_RedirectURI}}error{{end}}">
 | 
			
		||||
					<label for="redirect-uri">{{.i18n.Tr "settings.oauth2_redirect_uri"}}</label>
 | 
			
		||||
					<input type="url" name="redirect_uri" value="{{.App.PrimaryRedirectURI}}" id="redirect-uri">
 | 
			
		||||
				</div>
 | 
			
		||||
				<button class="ui green button">
 | 
			
		||||
					{{.i18n.Tr "settings.save_application"}}
 | 
			
		||||
				</button>
 | 
			
		||||
			</form>
 | 
			
		||||
		</div>
 | 
			
		||||
	</div>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<div class="ui small basic delete modal" id="delete-oauth2-application">
 | 
			
		||||
	<div class="ui icon header">
 | 
			
		||||
		<i class="trash icon"></i>
 | 
			
		||||
		{{.i18n.Tr "settings.remove_oauth2_application"}}
 | 
			
		||||
	</div>
 | 
			
		||||
	<div class="content">
 | 
			
		||||
		<p>{{.i18n.Tr "settings.remove_oauth2_application_desc"}}</p>
 | 
			
		||||
	</div>
 | 
			
		||||
	{{template "base/delete_modal_actions" .}}
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
{{template "base/footer" .}}
 | 
			
		||||
		Reference in New Issue
	
	Block a user