-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref DEV-2301
- Loading branch information
Showing
21 changed files
with
944 additions
and
41 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
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
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,154 @@ | ||
package graphql | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
|
||
relay "github.com/authgear/graphql-go-relay" | ||
Check failure on line 7 in pkg/portal/graphql/sms_mutation.go GitHub Actions / checks / authgear-test
Check failure on line 7 in pkg/portal/graphql/sms_mutation.go GitHub Actions / checks / authgear-test
Check failure on line 7 in pkg/portal/graphql/sms_mutation.go GitHub Actions / checks / authgear-test
|
||
"github.com/graphql-go/graphql" | ||
|
||
"github.com/authgear/authgear-server/pkg/api/apierrors" | ||
"github.com/authgear/authgear-server/pkg/lib/config" | ||
"github.com/authgear/authgear-server/pkg/portal/model" | ||
) | ||
|
||
var sendTestSMSInput = graphql.NewInputObject(graphql.InputObjectConfig{ | ||
Name: "SendTestSMSInput", | ||
Fields: graphql.InputObjectConfigFieldMap{ | ||
"appID": &graphql.InputObjectFieldConfig{ | ||
Type: graphql.NewNonNull(graphql.ID), | ||
Description: "App ID to test.", | ||
}, | ||
"to": &graphql.InputObjectFieldConfig{ | ||
Type: graphql.NewNonNull(graphql.String), | ||
Description: "The recipient phone number.", | ||
}, | ||
"providerConfiguration": &graphql.InputObjectFieldConfig{ | ||
Type: graphql.NewNonNull(smsProviderConfigurationInput), | ||
Description: "The SMS provider configuration.", | ||
}, | ||
}, | ||
}) | ||
|
||
var smsProviderConfigurationInput = graphql.NewInputObject(graphql.InputObjectConfig{ | ||
Name: "SMSProviderConfigurationInput", | ||
Fields: graphql.InputObjectConfigFieldMap{ | ||
"twilio": &graphql.InputObjectFieldConfig{ | ||
Type: smsProviderConfigurationTwilioInput, | ||
Description: "Twilio configuration", | ||
}, | ||
"webhook": &graphql.InputObjectFieldConfig{ | ||
Type: smsProviderConfigurationWebhookInput, | ||
Description: "Webhook Configuration", | ||
}, | ||
"deno": &graphql.InputObjectFieldConfig{ | ||
Type: smsProviderConfigurationDenoInput, | ||
Description: "Deno hook configuration", | ||
}, | ||
}, | ||
}) | ||
|
||
var smsProviderConfigurationTwilioInput = graphql.NewInputObject(graphql.InputObjectConfig{ | ||
Name: "SMSProviderConfigurationTwilioInput", | ||
Fields: graphql.InputObjectConfigFieldMap{ | ||
"accountSID": &graphql.InputObjectFieldConfig{ | ||
Type: graphql.NewNonNull(graphql.String), | ||
}, | ||
"authToken": &graphql.InputObjectFieldConfig{ | ||
Type: graphql.NewNonNull(graphql.String), | ||
}, | ||
"messagingServiceSID": &graphql.InputObjectFieldConfig{ | ||
Type: graphql.String, | ||
}, | ||
}, | ||
}) | ||
|
||
var smsProviderConfigurationWebhookInput = graphql.NewInputObject(graphql.InputObjectConfig{ | ||
Name: "SMSProviderConfigurationWebhookInput", | ||
Fields: graphql.InputObjectConfigFieldMap{ | ||
"url": &graphql.InputObjectFieldConfig{ | ||
Type: graphql.NewNonNull(graphql.String), | ||
}, | ||
"timeout": &graphql.InputObjectFieldConfig{ | ||
Type: graphql.Int, | ||
}, | ||
}, | ||
}) | ||
|
||
var smsProviderConfigurationDenoInput = graphql.NewInputObject(graphql.InputObjectConfig{ | ||
Name: "SMSProviderConfigurationDenoInput", | ||
Fields: graphql.InputObjectConfigFieldMap{ | ||
"script": &graphql.InputObjectFieldConfig{ | ||
Type: graphql.NewNonNull(graphql.String), | ||
}, | ||
"timeout": &graphql.InputObjectFieldConfig{ | ||
Type: graphql.Int, | ||
}, | ||
}, | ||
}) | ||
|
||
var _ = registerMutationField( | ||
"sendTestSMSConfiguration", | ||
&graphql.Field{ | ||
Description: "Send a SMS to test the configuration", | ||
Type: graphql.Boolean, | ||
Args: graphql.FieldConfigArgument{ | ||
"input": &graphql.ArgumentConfig{ | ||
Type: graphql.NewNonNull(sendTestSMSInput), | ||
}, | ||
}, | ||
Resolve: func(p graphql.ResolveParams) (interface{}, error) { | ||
input := p.Args["input"].(map[string]interface{}) | ||
appNodeID := input["appID"].(string) | ||
to := input["to"].(string) | ||
providerConfigurationInput := input["providerConfiguration"] | ||
|
||
resolvedNodeID := relay.FromGlobalID(appNodeID) | ||
if resolvedNodeID == nil || resolvedNodeID.Type != typeApp { | ||
return nil, apierrors.NewInvalid("invalid app ID") | ||
} | ||
appID := resolvedNodeID.ID | ||
|
||
ctx := p.Context | ||
gqlCtx := GQLContext(ctx) | ||
|
||
// Access control: collaborator. | ||
_, err := gqlCtx.AuthzService.CheckAccessOfViewer(ctx, appID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
app, err := gqlCtx.AppService.Get(ctx, appID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
providerConfigJSON, err := json.Marshal(providerConfigurationInput) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var providerConfig model.SMSProviderConfigurationInput | ||
err = json.Unmarshal(providerConfigJSON, &providerConfig) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
webhookSecretLoader := func(ctx context.Context) (*config.WebhookKeyMaterials, error) { | ||
return gqlCtx.AppService.LoadAppWebhookSecretMaterials(ctx, app) | ||
} | ||
|
||
err = gqlCtx.SMSService.SendTestSMS( | ||
ctx, | ||
app, | ||
to, | ||
webhookSecretLoader, | ||
providerConfig, | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return nil, nil | ||
}, | ||
}, | ||
) |
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,23 @@ | ||
package model | ||
|
||
type SMSProviderConfigurationInput struct { | ||
Twilio *SMSProviderConfigurationTwilioInput `json:"twilio,omitempty"` | ||
Webhook *SMSProviderConfigurationWebhookInput `json:"webhook,omitempty"` | ||
Deno *SMSProviderConfigurationDenoInput `json:"deno,omitempty"` | ||
} | ||
|
||
type SMSProviderConfigurationTwilioInput struct { | ||
AccountSID string `json:"accountSID,omitempty"` | ||
AuthToken string `json:"authToken,omitempty"` | ||
MessagingServiceSID *string `json:"messagingServiceSID,omitempty"` | ||
} | ||
|
||
type SMSProviderConfigurationWebhookInput struct { | ||
URL string `json:"url,omitempty"` | ||
Timeout *int `json:"timeout,omitempty"` | ||
} | ||
|
||
type SMSProviderConfigurationDenoInput struct { | ||
Script string `json:"script,omitempty"` | ||
Timeout *int `json:"timeout,omitempty"` | ||
} |
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,38 @@ | ||
package sms | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/google/wire" | ||
|
||
"github.com/authgear/authgear-server/pkg/portal/model" | ||
"github.com/authgear/authgear-server/pkg/util/resource" | ||
"github.com/authgear/authgear-server/pkg/util/template" | ||
) | ||
|
||
var DependencySet = wire.NewSet( | ||
NewLogger, | ||
wire.Struct(new(Service), "*"), | ||
) | ||
|
||
type NoopStaticAssetResolver struct{} | ||
|
||
func (r *NoopStaticAssetResolver) StaticAssetURL(ctx context.Context, id string) (url string, err error) { | ||
panic("NoopStaticAssetResolver is not supposed to be reachable") | ||
} | ||
|
||
func ProvideStaticAssetResolver() *NoopStaticAssetResolver { | ||
return &NoopStaticAssetResolver{} | ||
} | ||
|
||
func ProvideResourceManager(app *model.App) *resource.Manager { | ||
return app.Context.Resources | ||
} | ||
|
||
func ProvideDefaultLanguageTag(app *model.App) template.DefaultLanguageTag { | ||
return template.DefaultLanguageTag(*app.Context.Config.AppConfig.Localization.FallbackLanguage) | ||
} | ||
|
||
func ProvideSupportedLanguageTags(app *model.App) template.SupportedLanguageTags { | ||
return template.SupportedLanguageTags(app.Context.Config.AppConfig.Localization.SupportedLanguages) | ||
} |
Oops, something went wrong.