-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Integrate OAuth2 Provider #5378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
92 commits
Select commit
Hold shift + click to select a range
fb1bab1
Add oauth2 application
jonasfranz 8b9fb4c
Update index.css
kolaente 4b18995
Merge remote-tracking branch 'origin/master' into feature/oauth2
jonasfranz 8a2e6f1
Add grant and redirection
jonasfranz 6752e1a
Small improvements
jonasfranz ee833d1
Add documentation and missing vendors
jonasfranz 114cf36
Merge branch 'master' into feature/oauth2
jonasfranz cabbbd9
Revert unwanted changes
jonasfranz 6c5ddfb
Merge remote-tracking branch 'origin/master' into feature/oauth2
jonasfranz ccb990a
Merge branch 'feature/oauth2' of github.com:JonasFranzDEV/gitea into …
jonasfranz 04d3420
Merge branch 'feature/oauth2' of github.com:JonasFranzDEV/gitea into …
jonasfranz de7210f
Add copyright headers
jonasfranz 25793e6
Add access token cleanup cronjob
jonasfranz e5435ed
Merge branch 'master' of https://github.com/go-gitea/gitea into featu…
jonasfranz bd311a6
Use JWT tokens instead of "access tokens"
jonasfranz fd162c1
Fix some lint and documentation problems
jonasfranz fb2735c
Fix misspells
jonasfranz 0c07b84
Remove unsused access tokens model changes
jonasfranz 51ffa8a
Add auth code invalidation
jonasfranz 0648d41
Ensure gopkg
jonasfranz 3899a2e
Add oauth2 ui
jonasfranz 1d7316c
Check OAuth2 token
jonasfranz dce746a
Merge branch 'feature/oauth2' into feature/oauth2-ui
jonasfranz ee44838
Change authorize and access token endpoint
jonasfranz f8b099a
Merge remote-tracking branch 'jonas/feature/oauth2' into feature/oauth2
jonasfranz 869589e
Merge branch 'feature/oauth2' into feature/oauth2-ui
jonasfranz e334f2a
Merge branch 'master' into feature/oauth2
jonasfranz 8773029
Merge branch 'master' of https://github.com/go-gitea/gitea into featu…
jonasfranz f1ff7c9
Add counter for preventing using a refresh token twice
jonasfranz d4cc413
Merge branch 'feature/oauth2' into feature/oauth2-ui
jonasfranz ef14bf7
Improved the counter mechanics
jonasfranz 31112ee
Merge branch 'feature/oauth2' into feature/oauth2-ui
jonasfranz df63692
Fix increase counter
jonasfranz f7b7173
Merge remote-tracking branch 'jonas/feature/oauth2' into feature/oauth2
jonasfranz 68a0736
Add comments and fmt
jonasfranz 8a95e72
Merge branch 'master' into feature/oauth2
jonasfranz 72f4ec8
Merge branch 'master' into feature/oauth2
jonasfranz 93c9994
Merge branch 'master' into feature/oauth2
kolaente a892670
Add PKCE support
jonasfranz 8db5aba
Merge remote-tracking branch 'jonas/feature/oauth2' into feature/oauth2
jonasfranz a57014a
Merge branch 'master' into feature/oauth2
jonasfranz 2b737a1
Add some unit tests for oauth2_applications
jonasfranz ddb4244
Merge remote-tracking branch 'jonas/feature/oauth2' into feature/oauth2
jonasfranz 3116afc
Remove unused test
jonasfranz a89c4de
gofmt
jonasfranz 6e96c77
Merge branch 'master' into feature/oauth2
jonasfranz 14270e1
Add additional tests for OAuth2
jonasfranz 0ab5390
Merge branch 'master' of https://github.com/go-gitea/gitea into featu…
jonasfranz a4bc672
Merge branch 'master' into feature/oauth2
jonasfranz 84b927d
Merge branch 'jo/feature/oauth2' into jo/feature/oauth2-ui
kolaente d942c57
Add better secret
jonasfranz f874fc9
added new fancy design
kolaente e2919f8
Merge branch 'jo/feature/oauth2-ui' into jo/feature/oauth2
kolaente 3a853e6
Merged ui branch
kolaente 96fea41
Removed unnessecary types
kolaente 72c734c
fixed type not working
kolaente edf900f
Removed unnessecary types
kolaente d1a2a02
Removed more unnecessary stuff
kolaente e0b9307
fixed tests
kolaente 9ce3a3e
Add additional integration tests
jonasfranz 7e7d524
Merge remote-tracking branch 'jonas/feature/oauth2' into feature/oauth2
jonasfranz e8baddb
UI improvements
kolaente d645c00
Fixed lint
kolaente 124eab9
Show secrets after generating them
kolaente 8143eeb
Merge branch 'master' into feature/oauth2
kolaente 6e3b4c8
Merge remote-tracking branch 'jonas/feature/oauth2' into feature/oauth2
jonasfranz b26df39
Add additional integrations tests
jonasfranz f082e40
Merge branch 'master' of ssh://github.com/go-gitea/gitea into feature…
jonasfranz 7250d4a
Add remove functionality to application settings
jonasfranz e58c161
Add edit functionality
jonasfranz 792d8e5
Add copyright headers
jonasfranz 3fcfdb5
Add regenerated stylessheet
jonasfranz 7370e05
Merge branch 'master' into feature/oauth2
jonasfranz 82102fa
Fix pgsql/mssql failures with increase counter
jonasfranz c193062
Merge branch 'master' into feature/oauth2
jonasfranz a428f1a
Fix wrong bearer detection
jonasfranz 6278b7a
Merge remote-tracking branch 'jonas/feature/oauth2' into feature/oauth2
jonasfranz 2b55fbb
Merge branch 'master' of https://github.com/go-gitea/gitea into featu…
jonasfranz c2243c9
Update CSS
jonasfranz 5740c12
Apply changes by @lunny
jonasfranz 2262795
Use session to delete applications
jonasfranz 49e2fac
Merge branch 'master' of https://github.com/go-gitea/gitea into featu…
jonasfranz 4bcc28b
Use separate json tag for grant_id
jonasfranz dc8dc55
Move session begin and commit
jonasfranz 141ae6b
Add authorization error page
jonasfranz bdf6643
Merge remote-tracking branch 'jonas/feature/oauth2' into feature/oauth2
jonasfranz 709e8d5
Add login as reserved username
jonasfranz 5c31409
Merge branch 'master' of https://github.com/go-gitea/gitea into featu…
jonasfranz b3c6962
Merge branch 'master' into feature/oauth2
jonasfranz 9e27fea
Merge branch 'master' into feature/oauth2
techknowlogick ff266f4
generate stylesheets
techknowlogick 9d11393
status 400 instead of 500 because error is with user not server
techknowlogick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
// Copyright 2019 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package integrations | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
const defaultAuthorize = "/login/oauth/authorize?client_id=da7da3ba-9a13-4167-856f-3899de0b0138&redirect_uri=a&response_type=code&state=thestate" | ||
|
||
func TestNoClientID(t *testing.T) { | ||
prepareTestEnv(t) | ||
req := NewRequest(t, "GET", "/login/oauth/authorize") | ||
ctx := loginUser(t, "user2") | ||
ctx.MakeRequest(t, req, 400) | ||
} | ||
|
||
func TestLoginRedirect(t *testing.T) { | ||
prepareTestEnv(t) | ||
req := NewRequest(t, "GET", "/login/oauth/authorize") | ||
assert.Contains(t, MakeRequest(t, req, 302).Body.String(), "/user/login") | ||
} | ||
|
||
func TestShowAuthorize(t *testing.T) { | ||
prepareTestEnv(t) | ||
req := NewRequest(t, "GET", defaultAuthorize) | ||
ctx := loginUser(t, "user4") | ||
resp := ctx.MakeRequest(t, req, 200) | ||
|
||
htmlDoc := NewHTMLParser(t, resp.Body) | ||
htmlDoc.AssertElement(t, "#authorize-app", true) | ||
htmlDoc.GetCSRF() | ||
} | ||
|
||
func TestRedirectWithExistingGrant(t *testing.T) { | ||
prepareTestEnv(t) | ||
req := NewRequest(t, "GET", defaultAuthorize) | ||
ctx := loginUser(t, "user1") | ||
resp := ctx.MakeRequest(t, req, 302) | ||
u, err := resp.Result().Location() | ||
assert.NoError(t, err) | ||
assert.Equal(t, "thestate", u.Query().Get("state")) | ||
assert.Truef(t, len(u.Query().Get("code")) > 30, "authorization code '%s' should be longer then 30", u.Query().Get("code")) | ||
} | ||
|
||
func TestAccessTokenExchange(t *testing.T) { | ||
prepareTestEnv(t) | ||
req := NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{ | ||
"grant_type": "authorization_code", | ||
"client_id": "da7da3ba-9a13-4167-856f-3899de0b0138", | ||
"client_secret": "4MK8Na6R55smdCY0WuCCumZ6hjRPnGY5saWVRHHjJiA=", | ||
"redirect_uri": "a", | ||
"code": "authcode", | ||
"code_verifier": "N1Zo9-8Rfwhkt68r1r29ty8YwIraXR8eh_1Qwxg7yQXsonBt", // test PKCE additionally | ||
}) | ||
resp := MakeRequest(t, req, 200) | ||
type response struct { | ||
AccessToken string `json:"access_token"` | ||
TokenType string `json:"token_type"` | ||
ExpiresIn int64 `json:"expires_in"` | ||
RefreshToken string `json:"refresh_token"` | ||
} | ||
parsed := new(response) | ||
assert.NoError(t, json.Unmarshal(resp.Body.Bytes(), parsed)) | ||
assert.True(t, len(parsed.AccessToken) > 10) | ||
assert.True(t, len(parsed.RefreshToken) > 10) | ||
} | ||
|
||
func TestAccessTokenExchangeWithoutPKCE(t *testing.T) { | ||
prepareTestEnv(t) | ||
req := NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{ | ||
"grant_type": "authorization_code", | ||
"client_id": "da7da3ba-9a13-4167-856f-3899de0b0138", | ||
"client_secret": "4MK8Na6R55smdCY0WuCCumZ6hjRPnGY5saWVRHHjJiA=", | ||
"redirect_uri": "a", | ||
"code": "authcode", | ||
}) | ||
MakeRequest(t, req, 400) | ||
} | ||
|
||
func TestAccessTokenExchangeWithInvalidCredentials(t *testing.T) { | ||
prepareTestEnv(t) | ||
// invalid client id | ||
req := NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{ | ||
"grant_type": "authorization_code", | ||
"client_id": "???", | ||
"client_secret": "4MK8Na6R55smdCY0WuCCumZ6hjRPnGY5saWVRHHjJiA=", | ||
"redirect_uri": "a", | ||
"code": "authcode", | ||
"code_verifier": "N1Zo9-8Rfwhkt68r1r29ty8YwIraXR8eh_1Qwxg7yQXsonBt", // test PKCE additionally | ||
}) | ||
MakeRequest(t, req, 400) | ||
// invalid client secret | ||
req = NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{ | ||
"grant_type": "authorization_code", | ||
"client_id": "da7da3ba-9a13-4167-856f-3899de0b0138", | ||
"client_secret": "???", | ||
"redirect_uri": "a", | ||
"code": "authcode", | ||
"code_verifier": "N1Zo9-8Rfwhkt68r1r29ty8YwIraXR8eh_1Qwxg7yQXsonBt", // test PKCE additionally | ||
}) | ||
MakeRequest(t, req, 400) | ||
// invalid redirect uri | ||
req = NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{ | ||
"grant_type": "authorization_code", | ||
"client_id": "da7da3ba-9a13-4167-856f-3899de0b0138", | ||
"client_secret": "4MK8Na6R55smdCY0WuCCumZ6hjRPnGY5saWVRHHjJiA=", | ||
"redirect_uri": "???", | ||
"code": "authcode", | ||
"code_verifier": "N1Zo9-8Rfwhkt68r1r29ty8YwIraXR8eh_1Qwxg7yQXsonBt", // test PKCE additionally | ||
}) | ||
MakeRequest(t, req, 400) | ||
// invalid authorization code | ||
req = NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{ | ||
"grant_type": "authorization_code", | ||
"client_id": "da7da3ba-9a13-4167-856f-3899de0b0138", | ||
"client_secret": "4MK8Na6R55smdCY0WuCCumZ6hjRPnGY5saWVRHHjJiA=", | ||
"redirect_uri": "a", | ||
"code": "???", | ||
"code_verifier": "N1Zo9-8Rfwhkt68r1r29ty8YwIraXR8eh_1Qwxg7yQXsonBt", // test PKCE additionally | ||
}) | ||
MakeRequest(t, req, 400) | ||
// invalid grant_type | ||
req = NewRequestWithValues(t, "POST", "/login/oauth/access_token", map[string]string{ | ||
"grant_type": "???", | ||
"client_id": "da7da3ba-9a13-4167-856f-3899de0b0138", | ||
"client_secret": "4MK8Na6R55smdCY0WuCCumZ6hjRPnGY5saWVRHHjJiA=", | ||
"redirect_uri": "a", | ||
"code": "authcode", | ||
"code_verifier": "N1Zo9-8Rfwhkt68r1r29ty8YwIraXR8eh_1Qwxg7yQXsonBt", // test PKCE additionally | ||
}) | ||
MakeRequest(t, req, 400) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
- | ||
id: 1 | ||
uid: 1 | ||
name: "Test" | ||
client_id: "da7da3ba-9a13-4167-856f-3899de0b0138" | ||
client_secret: "$2a$10$UYRgUSgekzBp6hYe8pAdc.cgB4Gn06QRKsORUnIYTYQADs.YR/uvi" # bcrypt of "4MK8Na6R55smdCY0WuCCumZ6hjRPnGY5saWVRHHjJiA= | ||
redirect_uris: '["a"]' | ||
created_unix: 1546869730 | ||
updated_unix: 1546869730 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
- id: 1 | ||
grant_id: 1 | ||
code: "authcode" | ||
code_challenge: "CjvyTLSdR47G5zYenDA-eDWW4lRrO8yvjcWwbD_deOg" # Code Verifier: N1Zo9-8Rfwhkt68r1r29ty8YwIraXR8eh_1Qwxg7yQXsonBt | ||
code_challenge_method: "S256" | ||
redirect_uri: "a" | ||
valid_until: 3546869730 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
- id: 1 | ||
user_id: 1 | ||
application_id: 1 | ||
counter: 1 | ||
created_unix: 1546869730 | ||
updated_unix: 1546869730 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.