Skip to content

Commit

Permalink
As an SDK user, I want to be able get app information from the SDKs (#15
Browse files Browse the repository at this point in the history
)

* add GetApp functionality
 - add test to app_test.go
  • Loading branch information
Chris Loper authored May 20, 2022
1 parent d956cd4 commit 8a942f9
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
68 changes: 68 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,74 @@ type MagicLink struct {
TTL int `json:"ttl"`
URL string `json:"url"`
}
type AppInfo struct {
Name string `json:"name"` // The name of the App
ID string `json:"id"` // The appID of the App
AuthOrigin string `json:"auth_origin"` // The url being used for the App's authentication
RedirectURL string `json:"redirect_url"` // Where users should be redirected on successful authentication
LoginURL string `json:"login_url"` // Where users should attempt to log in
PublicKey string `json:"rsa_public_key"` // The PublicKey associated with the app.
AllowedIdentifier string `json:"allowed_identifier"` // Which identifier(s) are allowed for this app (email, phone, both)
RequiredIdentifier string `json:"required_identifier"` // Which identifier(s) are required for this app (email, phone, either, both)
RequireEmailVerification bool `json:"require_email_verification"` // If this app require email verification
SessionTimeoutLength int `json:"session_timeout_length"` // How long a JWT will last for the app when a user logs in
UserMetadataSchemaResponse []UserMetadataField `json:"user_metadata_schema"` // The schema for user_metadata that will be stored about users
Layouts Layouts `json:"layouts"` // The layouts of user_metadata on the register/profile element
}
type UserMetadataField struct {
Handle string `json:"id"` // Unique id for the user metadata field
FieldName string `json:"field_name"` // The name that will be used in user requests to create/update user_metadata
FieldType UserMetadataFieldType `json:"type"` // The type of data stored in this field
FriendlyName string `json:"friendly_name"` // The human readable name for this field
Registration bool `json:"registration"` // Whether or not this field will be accepted on user registration
Profile bool `json:"profile"` // Whether or not this field can be updated via the passage-profile
}

type UserMetadataFieldType string

const (
StringMD UserMetadataFieldType = "string"
BooleanMD UserMetadataFieldType = "boolean"
NumberMD UserMetadataFieldType = "integer"
DateMD UserMetadataFieldType = "date"
PhoneMD UserMetadataFieldType = "phone"
EmailMD UserMetadataFieldType = "email"
)

type Layouts struct {
Registration []LayoutConfig `json:"registration"` // The UI layout for user_metadata in the passage-register/passage-auth element
Profile []LayoutConfig `json:"profile"` // The UI layout for user_metadata in the passage-profile element
}

type LayoutConfig struct {
ID string `json:"id"`
X uint `json:"x"`
Y uint `json:"y"`
W uint `json:"w"`
H uint `json:"h"`
}

// GetApp gets information about an app
// returns App on success, error on failure
func (a *App) GetApp() (*AppInfo, error) {
type respAppInfo struct {
App AppInfo `json:"app"`
}
var appResp respAppInfo

response, err := resty.New().R().
SetResult(&appResp).
Get(fmt.Sprintf("https://api.passage.id/v1/apps/%v", a.ID))
if err != nil {
return nil, errors.New("network error: could not get Passage App Info")
}
if response.StatusCode() != http.StatusOK {
return nil, fmt.Errorf("failed to get Passage App Info. Http Status: %v. Response: %v", response.StatusCode(), response.String())
}
fmt.Println(appResp)

return &appResp.App, nil
}

// CreateMagicLink receives a CreateMagicLinkBody struct, creating a magic link with provided values
// returns MagicLink on success, error on failure
Expand Down
12 changes: 12 additions & 0 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,15 @@ func TestCreateMagicLink(t *testing.T) {
assert.Equal(t, createMagicLinkBody.Email, magicLink.Identifier)
assert.Equal(t, createMagicLinkBody.TTL, magicLink.TTL)
}

func TestGetApp(t *testing.T) {
psg, err := passage.New(PassageAppID, &passage.Config{
APIKey: PassageApiKey, // An API_KEY environment variable is required for testing.
})
require.Nil(t, err)

appInfo, err := psg.GetApp()
assert.Nil(t, err)
assert.Equal(t, PassageAppID, appInfo.ID)

}

0 comments on commit 8a942f9

Please sign in to comment.