Skip to content

Commit

Permalink
Enable OAuth authentication method for Okta
Browse files Browse the repository at this point in the history
In addition to API tokens, support the auth
using an OAuth 2.0 service app credentials.
  • Loading branch information
Kristián Leško authored and Jared Murrell committed Apr 21, 2022
1 parent effc1e4 commit 4c57c64
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
20 changes: 18 additions & 2 deletions .env.example.okta
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,28 @@ USER_SYNC_ATTRIBUTE=username
###################
## Your organizations Okta URL
OKTA_ORG_URL=https://example.okta.com
## The bot's access token
OKTA_ACCESS_TOKEN=asdfghkjliptojkjsj00294759
## The attribute which corresponds to the GitHub Username
## NOTE: This cannot be an email address
OKTA_USERNAME_ATTRIBUTE=github_username

###############################
## Okta token authentication ##
###############################
## The bot's access token
OKTA_ACCESS_TOKEN=asdfghkjliptojkjsj00294759

###############################
## Okta OAuth authentication ##
###############################
## Auth method switch
OKTA_AUTH_METHOD=oauth
## Okta OIDC app client ID
OKTA_CLIENT_ID=abcdefghijkl
## Okta OIDC auth scopes
OKTA_SCOPES=okta.users.read
## Okta OIDC app private key (JWK format)
OKTA_PRIVATE_KEY='{"kty": "RSA", ...}'

#########################
## Additional settings ##
#########################
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,16 @@ AZURE_USER_IS_UPN=true
### Sample `.env` for Okta
```env
OKTA_ORG_URL=https://example.okta.com
OKTA_ACCESS_TOKEN=asdfghkjliptojkjsj00294759
OKTA_USERNAME_ATTRIBUTE=github_username
# token login
OKTA_ACCESS_TOKEN=asdfghkjliptojkjsj00294759
# OAuth login
OKTA_AUTH_METHOD=oauth
OKTA_CLIENT_ID=abcdefghijkl
OKTA_SCOPES=okta.users.read
OKTA_PRIVATE_KEY='{"kty": "RSA", ...}'
```

### Sample `.env` for OneLogin
Expand Down
13 changes: 9 additions & 4 deletions githubapp/okta.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@
class Okta:
def __init__(self):
self.USERNAME_ATTRIBUTE = os.environ.get("OKTA_USERNAME_ATTRIBUTE", "login")
config = {
"orgUrl": os.environ["OKTA_ORG_URL"],
"token": os.environ["OKTA_ACCESS_TOKEN"],
}
auth_method = os.environ.get("OKTA_AUTH_METHOD", "token")
config = {"orgUrl": os.environ["OKTA_ORG_URL"]}
if auth_method == "oauth":
config["authorizationMode"] = "PrivateKey"
config["clientId"] = os.environ["OKTA_CLIENT_ID"]
config["scopes"] = os.environ["OKTA_SCOPES"]
config["privateKey"] = os.environ["OKTA_PRIVATE_KEY"]
else:
config["token"] = os.environ["OKTA_ACCESS_TOKEN"]
self.client = OktaClient(config)

def get_group_members(self, group_name=None):
Expand Down

0 comments on commit 4c57c64

Please sign in to comment.