Skip to content

Commit

Permalink
use only auth token
Browse files Browse the repository at this point in the history
  • Loading branch information
streetturtle committed Nov 6, 2022
1 parent c196d32 commit 3b3dd49
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
4 changes: 2 additions & 2 deletions JiraBar/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ extension AppDelegate {
self.menu.addItem(refreshItem)

let openSearchResultsItem = NSMenuItem(title: "Open Search results", action: #selector(self.openSearchResults), keyEquivalent: "")
openSearchResultsItem.image = NSImage(systemSymbolName: "arrow.up.forward.app", accessibilityDescription: nil)
openSearchResultsItem.image = NSImage(systemSymbolName: "magnifyingglass", accessibilityDescription: nil)
self.menu.addItem(openSearchResultsItem)

let createNewItem = NSMenuItem(title: "Create issue", action: #selector(self.openCreateNewIssue), keyEquivalent: "")
createNewItem.image = NSImage(systemSymbolName: "plus.square", accessibilityDescription: nil)
createNewItem.image = NSImage(systemSymbolName: "plus", accessibilityDescription: nil)
self.menu.addItem(createNewItem)

self.menu.addItem(.separator())
Expand Down
1 change: 0 additions & 1 deletion JiraBar/Extensions/DefaultsExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Foundation
import Defaults

extension Defaults.Keys {
static let jiraUsername = Key<String>("jiraUsername", default: "")

static let jiraHost = Key<String>("jiraHost", default: "https://issues.apache.org/jira")
static let jql = Key<String>("jql", default: "")
Expand Down
19 changes: 9 additions & 10 deletions JiraBar/Jira/JiraClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import KeychainAccess


public class JiraClient {
@Default(.jiraUsername) var jiraUsername
@Default(.jiraHost) var jiraHost
@Default(.jql) var jql
@Default(.maxResults) var maxResults
Expand All @@ -24,8 +23,8 @@ public class JiraClient {
.accept("application/json")
]

if !jiraUsername.isEmpty && !jiraToken.isEmpty {
headers.add(.authorization(username: jiraUsername, password: jiraToken))
if !jiraToken.isEmpty {
headers.add(.authorization(bearerToken: jiraToken))
}

AF.request(url, method: .get, parameters: parameters, headers: headers)
Expand All @@ -49,11 +48,11 @@ public class JiraClient {
.accept("application/json")
]

if !jiraUsername.isEmpty && !jiraToken.isEmpty {
headers.add(.authorization(username: jiraUsername, password: jiraToken))
if !jiraToken.isEmpty {
headers.add(.authorization(bearerToken: jiraToken))
}

AF.request(url, method: .get, parameters: nil, headers: (!jiraUsername.isEmpty && !jiraToken.isEmpty) ? headers : nil)
AF.request(url, method: .get, parameters: nil, headers: headers)
.validate(statusCode: 200..<300)
.responseDecodable(of: TransitionsResponse.self) { response in
switch response.result {
Expand All @@ -80,8 +79,8 @@ public class JiraClient {
.contentType("application/json")
]

if !jiraUsername.isEmpty && !jiraToken.isEmpty {
headers.add(.authorization(username: jiraUsername, password: jiraToken))
if !jiraToken.isEmpty {
headers.add(.authorization(bearerToken: jiraToken))
}

AF.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: headers)
Expand All @@ -107,8 +106,8 @@ public class JiraClient {
.accept("application/json")
]

if !jiraUsername.isEmpty && !jiraToken.isEmpty {
headers.add(.authorization(username: jiraUsername, password: jiraToken))
if !jiraToken.isEmpty {
headers.add(.authorization(bearerToken: jiraToken))
}

AF.request(url, method: .get, parameters: nil, headers: headers)
Expand Down
3 changes: 0 additions & 3 deletions JiraBar/Views/PreferencesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import SwiftUI
import Defaults

struct PreferencesView: View {
@Default(.jiraUsername) var jiraUsername
@Default(.jiraHost) var jiraHost
@Default(.jql) var jql
@Default(.refreshRate) var refreshRate
Expand All @@ -20,8 +19,6 @@ struct PreferencesView: View {
Form {
TextField("Jira Host:", text: $jiraHost)
.textFieldStyle(RoundedBorderTextFieldStyle())
TextField("Jira Username:", text: $jiraUsername)
.textFieldStyle(RoundedBorderTextFieldStyle())
SecureField("Jira Token:", text: $jiraToken)
.textFieldStyle(RoundedBorderTextFieldStyle())
.overlay(
Expand Down

0 comments on commit 3b3dd49

Please sign in to comment.