-
Notifications
You must be signed in to change notification settings - Fork 20
Added Oauth setup and connect disconnect command #126
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 22 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
dd48231
refactored the code and added flow manager
Kshitij-Katiyar 8735616
removed unused code
Kshitij-Katiyar df14ae7
fixed lint
Kshitij-Katiyar b2b9222
added oauth setup and connect disconnect command
Kshitij-Katiyar a985f26
removed unrelated changes from package lock
Kshitij-Katiyar 548de42
fixed lint
Kshitij-Katiyar 4e352ae
fixed missing go mod entry
Kshitij-Katiyar 828fddb
removed unwanted code and added mutliple status code handling
Kshitij-Katiyar b34d300
fixed lint
Kshitij-Katiyar d18f2bd
fixed step title
Kshitij-Katiyar a906811
removed unwanted variables
Kshitij-Katiyar dfdd4a4
removed extra lines in flow instructions
Kshitij-Katiyar ad309d0
Merge branch 'flow_setup' of github.com:Brightscout/mattermost-plugin…
Kshitij-Katiyar 9551c0c
updated flow messages
Kshitij-Katiyar 550b82e
review fixes
Kshitij-Katiyar 2b88e55
Merge branch 'flow_setup' of github.com:mattermost-community/mattermo…
Kshitij-Katiyar 8070b28
fixed callJSONwithURL call
Kshitij-Katiyar 862b419
review fixes
Kshitij-Katiyar 4a7d4be
fixed lint
Kshitij-Katiyar 712958d
Merge branch 'flow_setup' of github.com:mattermost-community/mattermo…
Kshitij-Katiyar b5c88b6
fixed lint
Kshitij-Katiyar c43c30a
Added support for notification with server version greater than 9 (#127)
Kshitij-Katiyar ef69358
review fixes
Kshitij-Katiyar 51969de
review fixes
Kshitij-Katiyar 52329ad
removed unused code
Kshitij-Katiyar 91b85ec
fixed go mod enteries
Kshitij-Katiyar ce2dc09
merge with base
Kshitij-Katiyar 1478e36
removed external css sheet
Kshitij-Katiyar a20d86e
Merge branch 'oauth_epic' of github.com:mattermost-community/mattermo…
Kshitij-Katiyar d111eb3
review fixes
Kshitij-Katiyar 2dbe9bd
Merge branch 'oauth_epic' of github.com:mattermost-community/mattermo…
Kshitij-Katiyar 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
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,74 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <style> | ||
| body { | ||
| color: rgb(23, 43, 77); | ||
| letter-spacing: -0.01em; | ||
| } | ||
|
|
||
| .flex-parent { | ||
| padding: 50px; | ||
| } | ||
|
|
||
| .btn { | ||
| -webkit-transition: all 0.15s ease; | ||
| -moz-transition: all 0.15s ease; | ||
| -o-transition: all 0.15s ease; | ||
| transition: all 0.15s ease false; | ||
| padding: 0.5em 1em; | ||
| font-size: inherit; | ||
| border: none; | ||
| height: auto; | ||
| border-radius: 4px; | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| .btn-primary { | ||
| color: rgb(255, 255, 255); | ||
| background: rgb(0, 82, 204); | ||
| } | ||
|
|
||
| .btn-primary:hover, | ||
| .btn-primary:active { | ||
| background: rgb(0, 101, 255); | ||
| } | ||
|
|
||
| .accounts-container { | ||
| padding: 1.6em 0 0.8em; | ||
| opacity: 0.6; | ||
| } | ||
|
|
||
| .icon--check { | ||
| margin-right: 4px; | ||
| } | ||
|
|
||
| .message-container { | ||
| margin-top: 20px; | ||
| } | ||
| </style> | ||
| <script> | ||
| function closeTab() { | ||
| window.close(); | ||
| } | ||
| </script> | ||
| </head> | ||
| <body> | ||
| <div class="flex-parent"> | ||
| <h3> | ||
| <svg xmlns="http://www.w3.org/2000/svg" width="20" height="15" class="icon--check" viewBox="0 0 18 14"> | ||
| <path fill="#0052CC" d="M100.649576,76.1740942 C100.649576,76.4531124 100.537969,76.7321306 100.337075,76.9330237 L90.7388497,86.5312494 C90.5379566,86.7321425 90.2589384,86.8437498 89.9799202,86.8437498 C89.700902,86.8437498 89.4218838,86.7321425 89.2209908,86.5312494 L83.6629484,80.9732071 C83.4620553,80.772314 83.350448,80.4932958 83.350448,80.2142776 C83.350448,79.9352594 83.4620553,79.6562412 83.6629484,79.4553481 L85.1808074,77.9374892 C85.3817005,77.7365961 85.6607186,77.6249888 85.9397368,77.6249888 C86.218755,77.6249888 86.4977732,77.7365961 86.6986663,77.9374892 L89.9799202,81.2299038 L97.3013575,73.8973058 C97.5022506,73.6964127 97.7812688,73.5848054 98.060287,73.5848054 C98.3393052,73.5848054 98.6183234,73.6964127 98.8192165,73.8973058 L100.337075,75.4151648 C100.537969,75.6160579 100.649576,75.895076 100.649576,76.1740942 Z" transform="translate(-83 -73)"/> | ||
| </svg> | ||
| Mattermost user is now connected to Confluence | ||
| </h3> | ||
| <div class="accounts-container"> | ||
| <div>Mattermost account: {{ .MattermostDisplayName }}</div> | ||
| <div>Confluence account: {{ .ConfluenceDisplayName }}</div> | ||
| </div> | ||
| <div class="message-container"> | ||
| <p>You may now safely close this tab.</p> | ||
| <button class="btn btn-primary" onclick="closeTab()">Close Tab</button> | ||
| </div> | ||
| </div> | ||
| </body> | ||
| </html> |
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,31 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <style> | ||
| body { | ||
| color: rgb(23, 43, 77); | ||
| letter-spacing: -0.01em; | ||
| } | ||
|
|
||
| .flex-parent { | ||
| padding: 50px; | ||
| } | ||
|
|
||
| .message-container { | ||
| padding: 1.6em 0 0.8em; | ||
| opacity: .6; | ||
| } | ||
| </style> | ||
| <link rel="stylesheet" href="https://unpkg.com/@atlaskit/css-reset@2.0.0/dist/bundle.css" media="all"> | ||
| </head> | ||
| <body> | ||
| <div class="flex-parent"> | ||
| <h3> | ||
| {{ .Header}} | ||
| </h3> | ||
| <div class="message-container"> | ||
| <div>{{ .Message }}</div> | ||
| </div> | ||
| </div> | ||
| </body> | ||
| </html> | ||
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
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,131 @@ | ||
| // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. | ||
| // See License for license information. | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "crypto/aes" | ||
| "crypto/cipher" | ||
| "crypto/rand" | ||
| "encoding/base64" | ||
| "encoding/json" | ||
| "io" | ||
|
|
||
| "github.com/pkg/errors" | ||
| "golang.org/x/oauth2" | ||
|
|
||
| "github.com/mattermost/mattermost-plugin-confluence/server/config" | ||
| ) | ||
|
|
||
| type AuthToken struct { | ||
| Token *oauth2.Token `json:"token,omitempty"` | ||
| } | ||
|
|
||
| func (p *Plugin) NewEncodedAuthToken(token *oauth2.Token) (encodedToken string, returnErr error) { | ||
| encryptionSecret := config.GetConfig().EncryptionKey | ||
|
|
||
| t := AuthToken{ | ||
| Token: token, | ||
| } | ||
|
|
||
| jsonBytes, err := json.Marshal(t) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| encrypted, err := encrypt(jsonBytes, []byte(encryptionSecret)) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| return encode(encrypted), nil | ||
| } | ||
|
|
||
| func (p *Plugin) ParseAuthToken(encoded string) (token *oauth2.Token, returnErr error) { | ||
| t := AuthToken{} | ||
| encryptionSecret := config.GetConfig().EncryptionKey | ||
|
|
||
| decoded, err := decode(encoded) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| jsonBytes, err := decrypt(decoded, []byte(encryptionSecret)) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| if err = json.Unmarshal(jsonBytes, &t); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return t.Token, nil | ||
| } | ||
|
|
||
| func encode(encrypted []byte) string { | ||
| encoded := make([]byte, base64.URLEncoding.EncodedLen(len(encrypted))) | ||
| base64.URLEncoding.Encode(encoded, encrypted) | ||
| return string(encoded) | ||
| } | ||
|
|
||
| func encrypt(plain, secret []byte) ([]byte, error) { | ||
| if len(secret) == 0 { | ||
| return plain, nil | ||
| } | ||
|
|
||
| block, err := aes.NewCipher(secret) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| aesgcm, err := cipher.NewGCM(block) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| nonce := make([]byte, aesgcm.NonceSize()) | ||
| if _, err = io.ReadFull(rand.Reader, nonce); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| sealed := aesgcm.Seal(nil, nonce, plain, nil) | ||
| return append(nonce, sealed...), nil | ||
| } | ||
|
|
||
| func decode(encoded string) ([]byte, error) { | ||
| decoded := make([]byte, base64.URLEncoding.DecodedLen(len(encoded))) | ||
| n, err := base64.URLEncoding.Decode(decoded, []byte(encoded)) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return decoded[:n], nil | ||
| } | ||
|
|
||
| func decrypt(encrypted, secret []byte) ([]byte, error) { | ||
| if len(secret) == 0 { | ||
| return encrypted, nil | ||
| } | ||
|
|
||
| block, err := aes.NewCipher(secret) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| aesgcm, err := cipher.NewGCM(block) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| nonceSize := aesgcm.NonceSize() | ||
| if len(encrypted) < nonceSize { | ||
| return nil, errors.New("token too short") | ||
| } | ||
|
|
||
| nonce, encrypted := encrypted[:nonceSize], encrypted[nonceSize:] | ||
| plain, err := aesgcm.Open(nil, nonce, encrypted, nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return plain, nil | ||
| } |
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,18 @@ | ||
| package main | ||
|
|
||
| import "github.com/mattermost/mattermost-plugin-confluence/server/util/types" | ||
|
|
||
| // Client is the combined interface for all upstream APIs and convenience methods. | ||
| type Client interface { | ||
| RESTService | ||
| } | ||
|
|
||
| // RESTService is the low-level interface for invoking the upstream service. | ||
| // Endpoint can be a "short" API URL path, including the version desired, like "v3/user", | ||
| // or a fully-qualified URL, with a non-empty scheme. | ||
| type RESTService interface { | ||
| GetSelf() (*types.ConfluenceUser, error) | ||
| GetSpaceData(string) (*SpaceResponse, error) | ||
| GetPageData(int) (*PageResponse, error) | ||
| GetSpaceKeyFromSpaceID(int64) (string, error) | ||
| } |
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.