generated from hpi-swa-teaching/SWT-Demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor authentication. Detect garbage token or token with not suffi…
…cient scopes
- Loading branch information
Matthias Cram
committed
Aug 2, 2022
1 parent
26b0438
commit 07f17df
Showing
66 changed files
with
251 additions
and
44 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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 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
File renamed without changes.
7 changes: 7 additions & 0 deletions
7
Squello-Core.package/SPBAuthenticator.class/class/newWith..st
This file contains 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,7 @@ | ||
instance creation | ||
newWith: anSPBGithubBoardProvider | ||
|
||
| instance | | ||
instance := self new. | ||
instance boardProvider: anSPBGithubBoardProvider. | ||
^ instance. |
11 changes: 11 additions & 0 deletions
11
Squello-Core.package/SPBAuthenticator.class/instance/authenticate.st
This file contains 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,11 @@ | ||
authentication | ||
authenticate | ||
|
||
self checkIfCredentialsMissing | ||
ifTrue: [SPBAuthenticationForm open]. | ||
|
||
self checkIfCredentialsMissing | ||
ifTrue: [self errorAuthenticationCanceled. Error signal]. | ||
|
||
[self checkIfTokenValidFor] | ||
on: Error do: [Error signal]. |
4 changes: 4 additions & 0 deletions
4
Squello-Core.package/SPBAuthenticator.class/instance/boardProvider..st
This file contains 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,4 @@ | ||
accessing | ||
boardProvider: anSPBGithubBoardProvider | ||
|
||
boardProvider := anSPBGithubBoardProvider. |
4 changes: 4 additions & 0 deletions
4
Squello-Core.package/SPBAuthenticator.class/instance/boardProvider.st
This file contains 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,4 @@ | ||
accessing | ||
boardProvider | ||
|
||
^ boardProvider. |
7 changes: 7 additions & 0 deletions
7
Squello-Core.package/SPBAuthenticator.class/instance/checkIfCredentialsMissing.st
This file contains 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,7 @@ | ||
authentication | ||
checkIfCredentialsMissing | ||
|
||
self username: SPBGithubAPI username. | ||
self token: SPBGithubAPI token. | ||
|
||
^ username isNil or: [token isNil]. |
16 changes: 16 additions & 0 deletions
16
Squello-Core.package/SPBAuthenticator.class/instance/checkIfTokenValidFor.st
This file contains 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,16 @@ | ||
authentication | ||
checkIfTokenValidFor | ||
|
||
| tokenScopes repo | | ||
[tokenScopes := self getTokenScopes] | ||
on: Error do: [Error signal]. | ||
|
||
"test if you can query the repo with this token" | ||
repo := self boardProvider getRepo. | ||
repo message = 'Not Found' | ||
ifTrue: | ||
[(tokenScopes includes: 'repo') | ||
ifTrue: [self errorRepoNotFound]. | ||
(tokenScopes includes: 'public_repo') | ||
ifTrue: [self errorInvalidTokenScopes]]. | ||
|
6 changes: 6 additions & 0 deletions
6
Squello-Core.package/SPBAuthenticator.class/instance/errorAuthenticationCanceled.st
This file contains 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 @@ | ||
errors | ||
errorAuthenticationCanceled | ||
|
||
UserDialogBoxMorph | ||
inform: 'Authentication dialog was dismissed' title: 'Operation canceled'. | ||
^ Error signal. |
7 changes: 7 additions & 0 deletions
7
Squello-Core.package/SPBAuthenticator.class/instance/errorGarbageToken.st
This file contains 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,7 @@ | ||
errors | ||
errorGarbageToken | ||
|
||
UserDialogBoxMorph | ||
inform: 'Not a valid token' title: 'Operation canceled'. | ||
SPBGithubAPI token: nil. | ||
^ Error signal. |
7 changes: 7 additions & 0 deletions
7
Squello-Core.package/SPBAuthenticator.class/instance/errorInvalidTokenScopes.st
This file contains 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,7 @@ | ||
errors | ||
errorInvalidTokenScopes | ||
|
||
UserDialogBoxMorph | ||
inform: 'Invalid token or username or repository is private. Token has only public_repo scope' title: 'Operation canceled'. | ||
SPBGithubAPI token: nil. | ||
^ Error signal. |
7 changes: 7 additions & 0 deletions
7
Squello-Core.package/SPBAuthenticator.class/instance/errorNoScopes.st
This file contains 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,7 @@ | ||
errors | ||
errorNoScopes | ||
|
||
UserDialogBoxMorph | ||
inform: 'Make sure the token has repo or public_repo scope' title: 'Operation cancelled'. | ||
SPBGithubAPI token: nil. | ||
^ Error signal. |
6 changes: 6 additions & 0 deletions
6
Squello-Core.package/SPBAuthenticator.class/instance/errorRepoNotFound.st
This file contains 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 @@ | ||
errors | ||
errorRepoNotFound | ||
|
||
UserDialogBoxMorph | ||
inform: 'Make sure you have access to the repository' title: 'Repository not found'. | ||
^ Error signal. |
9 changes: 9 additions & 0 deletions
9
Squello-Core.package/SPBAuthenticator.class/instance/getRepoFromUrl..st
This file contains 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 @@ | ||
authentication | ||
getRepoFromUrl: aString | ||
|
||
| pathComponents url | | ||
url := aString asUrl. | ||
pathComponents := url fullPath splitBy: '/'. | ||
self boardProvider user: (pathComponents at: 2). | ||
self boardProvider repo: (pathComponents at: 3). | ||
^ self boardProvider getRepo. |
13 changes: 13 additions & 0 deletions
13
Squello-Core.package/SPBAuthenticator.class/instance/getTokenScopes.st
This file contains 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,13 @@ | ||
authentication | ||
getTokenScopes | ||
|
||
| tokenScopes | | ||
tokenScopes := self boardProvider getTokenOAuthScopes. | ||
tokenScopes isEmpty | ||
ifTrue: [self errorGarbageToken]. | ||
|
||
(((tokenScopes includes: 'repo') not) and: [(tokenScopes includes: 'public_repo') not]) | ||
ifTrue: [self errorNoScopes]. | ||
^ tokenScopes. | ||
|
||
|
4 changes: 4 additions & 0 deletions
4
Squello-Core.package/SPBAuthenticator.class/instance/token..st
This file contains 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,4 @@ | ||
accessing | ||
token: aString | ||
|
||
token := aString. |
4 changes: 4 additions & 0 deletions
4
Squello-Core.package/SPBAuthenticator.class/instance/token.st
This file contains 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,4 @@ | ||
accessing | ||
token | ||
|
||
^ token. |
4 changes: 4 additions & 0 deletions
4
Squello-Core.package/SPBAuthenticator.class/instance/username..st
This file contains 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,4 @@ | ||
accessing | ||
username: aString | ||
|
||
username := aString. |
4 changes: 4 additions & 0 deletions
4
Squello-Core.package/SPBAuthenticator.class/instance/username.st
This file contains 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,4 @@ | ||
accessing | ||
username | ||
|
||
^ username. |
20 changes: 20 additions & 0 deletions
20
Squello-Core.package/SPBAuthenticator.class/methodProperties.json
This file contains 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,20 @@ | ||
{ | ||
"class" : { | ||
"newWith:" : "mcr 8/2/2022 17:38" }, | ||
"instance" : { | ||
"authenticate" : "mcr 8/2/2022 22:48", | ||
"boardProvider" : "mcr 8/2/2022 18:26", | ||
"boardProvider:" : "mcr 8/2/2022 18:26", | ||
"checkIfCredentialsMissing" : "mcr 8/2/2022 18:27", | ||
"checkIfTokenValidFor" : "mcr 8/2/2022 22:48", | ||
"errorAuthenticationCanceled" : "mcr 8/2/2022 21:49", | ||
"errorGarbageToken" : "mcr 8/2/2022 22:08", | ||
"errorInvalidTokenScopes" : "mcr 8/2/2022 22:54", | ||
"errorNoScopes" : "mcr 8/2/2022 22:31", | ||
"errorRepoNotFound" : "mcr 8/2/2022 21:50", | ||
"getRepoFromUrl:" : "mcr 8/2/2022 20:47", | ||
"getTokenScopes" : "mcr 8/2/2022 22:38", | ||
"token" : "mcr 8/2/2022 18:26", | ||
"token:" : "mcr 8/2/2022 18:26", | ||
"username" : "mcr 8/2/2022 18:27", | ||
"username:" : "mcr 8/2/2022 18:27" } } |
This file contains 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 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,5 @@ | ||
startup | ||
errorParsingUrl | ||
|
||
UserDialogBoxMorph | ||
inform: 'Invalid repository Url' title: 'Error parsing Url'. |
This file contains 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 |
---|---|---|
@@ -1,18 +1,18 @@ | ||
startup | ||
newWith: aString | ||
|
||
| instance username token | | ||
| instance authenticator | | ||
instance := self new. | ||
username := SPBGithubAPI username. | ||
token := SPBGithubAPI token. | ||
|
||
(username isNil or: [token isNil]) ifTrue: [SPBUserAuth open]. | ||
(username isNil or: [token isNil]) ifTrue: [^ UserDialogBoxMorph inform: 'Authentication dialog was dismissed' title: 'Operation canceled']. | ||
|
||
(aString beginsWith: 'https://github.com/') ifFalse: | ||
[^ UserDialogBoxMorph inform: 'Invalid repository url' asString title: 'Operation canceled']. | ||
|
||
instance | ||
loadProject: aString; | ||
buildAndOpen. | ||
[instance parseRepoFromUrl: aString] | ||
on: Error do: [self errorParsingUrl. ^ self]. | ||
|
||
authenticator := SPBAuthenticator newWith: instance boardProvider. | ||
[authenticator authenticate] | ||
on: Error do: [^ self]. | ||
|
||
[instance loadProject: aString] | ||
on: Error do: [^ self]. | ||
|
||
instance buildAndOpen. | ||
^ instance. |
This file contains 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
8 changes: 5 additions & 3 deletions
8
Squello-Core.package/SPBBoard.class/instance/errorInvalidUrl.st
This file contains 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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
toolbuilder | ||
initialize-release | ||
errorInvalidUrl | ||
|
||
UserDialogBoxMorph inform: 'Invalid repository url' title: 'Operation canceled'. | ||
|
||
UserDialogBoxMorph | ||
inform: 'Invalid repository Url or project does not exist' title: 'Operation canceled'. | ||
^ Error signal. |
6 changes: 6 additions & 0 deletions
6
Squello-Core.package/SPBBoard.class/instance/errorNoProjects.st
This file contains 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 @@ | ||
initialize-release | ||
errorNoProjects | ||
|
||
UserDialogBoxMorph | ||
inform: 'Repository has no projects' title: 'Operation canceled'. | ||
^ Error signal. |
This file contains 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
9 changes: 9 additions & 0 deletions
9
Squello-Core.package/SPBBoard.class/instance/parseRepoFromUrl..st
This file contains 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 @@ | ||
initialize-release | ||
parseRepoFromUrl: aString | ||
|
||
| pathComponents url | | ||
url := aString asUrl. | ||
pathComponents := url fullPath splitBy: '/'. | ||
self boardProvider user: (pathComponents at: 2). | ||
self boardProvider repo: (pathComponents at: 3). | ||
^ self boardProvider getRepo. |
This file contains 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 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
8 changes: 8 additions & 0 deletions
8
Squello-Core.package/SPBGithubAPI.class/instance/getRequestToURLHeaderOnly..st
This file contains 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 @@ | ||
request creation/sending | ||
getRequestToURLHeaderOnly: aString | ||
|
||
| request response | | ||
request := self createGetRequestTo: aString. | ||
response := (WebClient new initializeFromUrl: aString) sendRequest: request. | ||
|
||
^ response headers. |
10 changes: 10 additions & 0 deletions
10
Squello-Core.package/SPBGithubAPI.class/instance/getRequestToURLWithoutAuth..st
This file contains 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,10 @@ | ||
request creation/sending | ||
getRequestToURLWithoutAuth: aString | ||
|
||
| request response stream | | ||
request := self createGetRequestTo: aString. | ||
request removeHeader: 'Authorization'. | ||
response := (WebClient new initializeFromUrl: aString) sendRequest: request. | ||
stream := ReadStream on: response content from: 1 to: response content byteSize. | ||
|
||
^ Json readFrom: stream. |
9 changes: 9 additions & 0 deletions
9
Squello-Core.package/SPBGithubAPI.class/instance/queryScopeHeaderOnly..st
This file contains 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 @@ | ||
api calls get request | ||
queryScopeHeaderOnly: aString | ||
|
||
| url request response | | ||
url := 'https://api.github.com/users/' , aString. | ||
request := self createGetRequestTo: url. | ||
response := (WebClient new initializeFromUrl: url) sendRequest: request. | ||
|
||
^ response headersAt: 'X-OAuth-Scopes'. |
7 changes: 7 additions & 0 deletions
7
Squello-Core.package/SPBGithubAPI.class/instance/queryUser.repo..st
This file contains 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,7 @@ | ||
api calls get request | ||
queryUser: aString repo: anotherString | ||
|
||
| url | | ||
url := 'https://api.github.com/repos/', aString, '/', anotherString. | ||
|
||
^ self getRequestToURL: url. |
Oops, something went wrong.