-
-
Notifications
You must be signed in to change notification settings - Fork 958
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: implement offline scope in the way google expects (#3088)
- Loading branch information
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright © 2023 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package oidc_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"golang.org/x/oauth2" | ||
|
||
"github.com/ory/kratos/internal" | ||
"github.com/ory/kratos/selfservice/flow/login" | ||
"github.com/ory/kratos/selfservice/strategy/oidc" | ||
"github.com/ory/kratos/x" | ||
) | ||
|
||
func TestProviderGoogle_Scope(t *testing.T) { | ||
_, reg := internal.NewFastRegistryWithMocks(t) | ||
|
||
p := oidc.NewProviderGoogle(&oidc.Configuration{ | ||
Provider: "google", | ||
ID: "valid", | ||
ClientID: "client", | ||
ClientSecret: "secret", | ||
Mapper: "file://./stub/hydra.schema.json", | ||
RequestedClaims: nil, | ||
Scope: []string{"email", "profile", "offline_access"}, | ||
}, reg) | ||
|
||
c, _ := p.OAuth2(context.Background()) | ||
assert.NotContains(t, c.Scopes, "offline_access") | ||
} | ||
|
||
func TestProviderGoogle_AccessType(t *testing.T) { | ||
_, reg := internal.NewFastRegistryWithMocks(t) | ||
|
||
p := oidc.NewProviderGoogle(&oidc.Configuration{ | ||
Provider: "google", | ||
ID: "valid", | ||
ClientID: "client", | ||
ClientSecret: "secret", | ||
Mapper: "file://./stub/hydra.schema.json", | ||
RequestedClaims: nil, | ||
Scope: []string{"email", "profile", "offline_access"}, | ||
}, reg) | ||
|
||
r := &login.Flow{ | ||
ID: x.NewUUID(), | ||
} | ||
|
||
options := p.AuthCodeURLOptions(r) | ||
assert.Contains(t, options, oauth2.AccessTypeOffline) | ||
} |