Skip to content

Commit

Permalink
feat: azure oidc fix (#1349)
Browse files Browse the repository at this point in the history
Allows the use of Azure ID tokens with various Azure issuers, and
defaults to the common issuer.
  • Loading branch information
hf authored Dec 17, 2023
1 parent 757989c commit 97b3595
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/api/provider/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (g azureProvider) GetOAuthToken(code string) (*oauth2.Token, error) {
return g.Exchange(context.Background(), code)
}

func (g azureProvider) detectIDTokenIssuer(ctx context.Context, idToken string) (string, error) {
func DetectAzureIDTokenIssuer(ctx context.Context, idToken string) (string, error) {
var payload struct {
Issuer string `json:"iss"`
}
Expand All @@ -116,7 +116,7 @@ func (g azureProvider) GetUserData(ctx context.Context, tok *oauth2.Token) (*Use
idToken := tok.Extra("id_token")

if idToken != nil {
issuer, err := g.detectIDTokenIssuer(ctx, idToken.(string))
issuer, err := DetectAzureIDTokenIssuer(ctx, idToken.(string))
if err != nil {
return nil, err
}
Expand Down
11 changes: 9 additions & 2 deletions internal/api/token_oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,17 @@ func (p *IdTokenGrantParams) getProvider(ctx context.Context, config *conf.Globa
issuer = provider.IssuerGoogle
acceptableClientIDs = append(acceptableClientIDs, config.External.Google.ClientID...)

case p.Provider == "azure" || p.Issuer == provider.IssuerAzureCommon || p.Issuer == provider.IssuerAzureOrganizations:
case p.Provider == "azure" || provider.IsAzureIssuer(p.Issuer):
issuer = p.Issuer
if issuer == "" || !provider.IsAzureIssuer(issuer) {
detectedIssuer, err := provider.DetectAzureIDTokenIssuer(ctx, p.IdToken)
if err != nil {
return nil, nil, "", nil, badRequestError("Unable to detect issuer in ID token for Azure provider").WithInternalError(err)
}
issuer = detectedIssuer
}
cfg = &config.External.Azure
providerType = "azure"
issuer = p.Issuer
acceptableClientIDs = append(acceptableClientIDs, config.External.Azure.ClientID...)

case p.Provider == "facebook" || p.Issuer == provider.IssuerFacebook:
Expand Down
4 changes: 4 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,14 @@ paths:
enum:
- google
- apple
- azure
- facebook
- keycloak
client_id:
type: string
issuer:
type: string
description: If `provider` is `azure` then you can specify any Azure OIDC issuer string here, which will be used for verification.
gotrue_meta_security:
$ref: "#/components/schemas/GoTrueMetaSecurity"
auth_code:
Expand Down

0 comments on commit 97b3595

Please sign in to comment.