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(api): basic support for openid-connect authentication provider #5393

Merged
merged 8 commits into from
Aug 27, 2020
11 changes: 6 additions & 5 deletions engine/api/authentication/oidc/openid.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package oidc

import (
"context"
"errors"
"fmt"
"net/http"
"time"
Expand Down Expand Up @@ -106,7 +107,7 @@ func (d authDriver) GetUserInfo(ctx context.Context, req sdk.AuthConsumerSigninR
}
rawIDToken, ok := oauth2Token.Extra("id_token").(string)
if !ok {
return info, sdk.WrapError(err, "No id_token field in oauth2 token")
return info, sdk.WithStack(fmt.Errorf("no id_token field in oauth2 token"))
}
idToken, err := d.Verifier.Verify(ctx, rawIDToken)
if err != nil {
Expand All @@ -120,19 +121,19 @@ func (d authDriver) GetUserInfo(ctx context.Context, req sdk.AuthConsumerSigninR
// Check if email is verified.
// See standard claims at https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims
if verified, ok := tokenClaim["email_verified"].(bool); !ok || !verified {
return info, sdk.WrapError(sdk.ErrInvalidUser, "OIDC user's email not verified")
return info, sdk.NewErrorFrom(sdk.ErrInvalidUser, "OIDC user's email not verified")
}
if info.ExternalID, ok = tokenClaim["sub"].(string); !ok {
return info, sdk.WrapError(sdk.ErrInvalidUser, "Missing OIDC user ID in token claim")
return info, sdk.WithStack(errors.New("missing OIDC user ID in token claim"))
}

if info.Username, ok = tokenClaim["preferred_username"].(string); !ok {
return info, sdk.WrapError(sdk.ErrInvalidUser, "Missing username in OIDC token claim")
return info, sdk.WithStack(errors.New("Missing username in OIDC token claim"))
phsym marked this conversation as resolved.
Show resolved Hide resolved
}

info.Fullname, _ = tokenClaim["name"].(string)
if info.Email, ok = tokenClaim["email"].(string); !ok {
return info, sdk.WrapError(sdk.ErrInvalidUser, "Missing user's email in OIDC token claim")
return info, sdk.WithStack(errors.New("Missing user's email in OIDC token claim"))
phsym marked this conversation as resolved.
Show resolved Hide resolved
}

return info, nil
Expand Down