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

OIDC configurable consent scopes #280

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/core/lib/core/services/oauth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ defmodule Core.Services.OAuth do
"""
@spec get_consent(binary) :: {:ok, OIDCProvider.t} | error
def get_consent(challenge) do
with {:ok, %{client: client}} <- Hydra.get_consent(challenge) do
{:ok, Repositories.get_oidc_provider_by_client!(client.client_id)}
with {:ok, %{client: client, requested_scope: requested_scope, skip: skip}} <- Hydra.get_consent(challenge) do
{:ok, Repositories.get_oidc_provider_by_client!(client.client_id), requested_scope, skip}
end
end

Expand Down
8 changes: 7 additions & 1 deletion apps/graphql/lib/graphql/schema/oauth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ defmodule GraphQl.Schema.OAuth do
timestamps()
end

object :oauth_consent do
field :repository, :repository
field :requested_scope, list_of(:string)
field :skip, :boolean
end

connection node_type: :oidc_login

object :oauth_queries do
Expand All @@ -49,7 +55,7 @@ defmodule GraphQl.Schema.OAuth do
resolve &OAuth.resolve_login/2
end

field :oauth_consent, :repository do
field :oauth_consent, :oauth_consent do
arg :challenge, non_null(:string)

resolve &OAuth.resolve_consent/2
Expand Down
17 changes: 9 additions & 8 deletions www/src/components/oidc/OAuthConsent.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ import { GET_CONSENT, OAUTH_CONSENT } from './queries'
export function OAuthConsent() {
const location = useLocation()
const { consent_challenge: challenge } = queryString.parse(location.search)
const [mutation, { loading, error }] = useMutation(OAUTH_CONSENT, {
variables: { challenge, scopes: ['profile', 'openid'] },
onCompleted: ({ oauthConsent: { redirectTo } }) => {
window.location = redirectTo
},
})
const { data } = useQuery(GET_CONSENT, { variables: { challenge } })

if (!data) {
Expand All @@ -40,6 +34,13 @@ export function OAuthConsent() {

const { oauthConsent } = data

const [mutation, { loading, error }] = useMutation(OAUTH_CONSENT, {
variables: { challenge, scopes: oauthConsent.requested_scope },
onCompleted: ({ oauthConsent: { redirectTo } }) => {
window.location = redirectTo
},
})

return (
<LoginPortal>
<Box
Expand All @@ -60,11 +61,11 @@ export function OAuthConsent() {
/>
<Transaction size="15px" />
<RepoIcon
repo={oauthConsent}
repo={oauthConsent.repository}
size="60px"
/>
</Box>
<Text size="medium">{oauthConsent.name} would like access to your profile</Text>
<Text size="medium">{oauthConsent.repository.name} would like access to your profile</Text>
<Box
width="300px"
pad={{ vertical: 'small' }}
Expand Down