diff --git a/apps/core/lib/core/services/oauth.ex b/apps/core/lib/core/services/oauth.ex index 8a372eb95..1e11ec634 100644 --- a/apps/core/lib/core/services/oauth.ex +++ b/apps/core/lib/core/services/oauth.ex @@ -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 diff --git a/apps/graphql/lib/graphql/schema/oauth.ex b/apps/graphql/lib/graphql/schema/oauth.ex index ef9dbe808..f3bffe4bb 100644 --- a/apps/graphql/lib/graphql/schema/oauth.ex +++ b/apps/graphql/lib/graphql/schema/oauth.ex @@ -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 @@ -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 diff --git a/www/src/components/oidc/OAuthConsent.js b/www/src/components/oidc/OAuthConsent.js index 1e5435868..913aeb65d 100644 --- a/www/src/components/oidc/OAuthConsent.js +++ b/www/src/components/oidc/OAuthConsent.js @@ -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) { @@ -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 ( - {oauthConsent.name} would like access to your profile + {oauthConsent.repository.name} would like access to your profile