Skip to content
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

feat: add support for azure ad oauth #745

Merged
merged 2 commits into from
Sep 26, 2024

Conversation

0lionelzhang0
Copy link
Contributor

@0lionelzhang0 0lionelzhang0 commented Apr 1, 2024

With regards to #741
Adds support for Azure AD OAuth

@bugy
Copy link
Owner

bugy commented Aug 9, 2024

I'm so sorry for missing it. Will review it now


async def fetch_user_info(self, access_token) -> _OauthUserInfo:
headers = {'Authorization': f'Bearer {access_token}'}
user_response = await self.http_client.fetch('https://graph.microsoft.com/v1.0/me', headers=headers)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you try using the same approach as in GitlabOAuthAuthenticator? I.e. extend OAuth2Mixin and then make a request by

user = await self.oauth2_request(
            'https://graph.microsoft.com/v1.0/me',
            access_token=access_token)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I will try this next week!

Copy link
Contributor Author

@0lionelzhang0 0lionelzhang0 Aug 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, I wasn't able to get it to work with OAuth2Mixin. I would get unauthorized error 401. It might be that the Microsoft endpoint doesn't support the fetch methods of either embedding access token in URL or access token as POST request body (used by oauth2_request).
https://learn.microsoft.com/en-us/graph/auth-v2-user?tabs=http#request

^ Their example in this link only shows using the header method.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for trying!

src/auth/auth_azure_ad_oauth.py Show resolved Hide resolved
src/auth/auth_azure_ad_oauth.py Show resolved Hide resolved
@0lionelzhang0
Copy link
Contributor Author

Authentication.md wiki snippet:

## Azure AD OAuth

Script server can authenticate users via Azure AD OAuth. `auth_url`, `token_url`, `client_id`, and `secret` properties should be acquired from Azure and configured in the Script server.

### Instructions
- Log in to [Azure Portal](https://portal.azure.com).
- Click **Microsoft Entra ID** in the side menu. If you have access to more than one tenant, select your account in the upper right and set your session to the Entra ID tenant you wish to use.
- Under **Manage** in the side menu, click **App Registrations** > **New Registration**.
- Enter a descriptive name.
- Under **Redirect URI**, select the app type **Web**.
- Add the following redirect URLs:
  - `<script-server-url>/login.html`
  - `<script-server-url>`
- Click **Register**. The app’s Overview page opens.
- Note the **Application ID**. This is the OAuth client ID (`client_id`).
- Click **Endpoints** from the top menu.
  - Note the OAuth 2.0 authorization endpoint (v2) URL (`auth_url`).
  - Note the OAuth 2.0 token endpoint (v2) URL (`token_url`).
- Click **Certificates & secrets** in the side menu.
- Add a new entry under **Client secrets** with the following configuration:
  - **Description**: Grafana OAuth
  - **Expires**: Select an expiration period
- Click **Add** then copy the key value. This is the OAuth client secret (`secret`).

### Options
* `type` (required) - should be `azure_ad_oauth`
* `auth_url` (required) - e.g. `https://login.microsoftonline.com/<TENANT_ID>/oauth2/v2.0/authorize`
* `token_url` (required) - e.g. `https://login.microsoftonline.com/<TENANT_ID>/oauth2/v2.0/token`
* `client_id` (required) - OAuth client ID
* `secret` (required) - OAuth client secret

@bugy bugy merged commit 36e59f4 into bugy:master Sep 26, 2024
@bugy bugy added the feature label Sep 26, 2024
@bugy bugy added this to the 1.18.0 milestone Sep 26, 2024
@tvalenta
Copy link

tvalenta commented Oct 9, 2024

@bugy is there a dev release of this anywhere that can be downloaded?

@bugy
Copy link
Owner

bugy commented Oct 10, 2024

@tvalenta
Copy link

The dev release has a date of December 2023. Am I misreading it?

@bugy
Copy link
Owner

bugy commented Oct 10, 2024

@tvalenta oh, the build was not running for a long time already :(
I sent a message to travis team to provide more build credits, so the builds can run again.

@tvalenta
Copy link

@tvalenta oh, the build was not running for a long time already :( I sent a message to travis team to provide more build credits, so the builds can run again.

I'd like to give this build a try -- any chance cicd would now build the dev release?

@bugy
Copy link
Owner

bugy commented Oct 23, 2024

@tvalenta the build should be ready now :) sorry for delay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants